sql server - SQL - 2 Counts in one query -


i have 2 queries return counts of different information in table:

select date, count(*) total  table type = 7 , date >= '2010-01-01'  group date  having count(*) > 5000   order date 

which returns totals of 'busy' dates:

date       total ---------- ----------- 2010-01-05 9466 2010-02-02 8747 2010-03-02 9010 2010-04-06 7916 2010-05-05 9342 2010-06-02 8723 2010-07-02 7829 2010-08-03 8411 2010-09-02 7687 2010-10-04 7706 2010-11-02 8567 2010-12-02 7645 

and

select date, count(*) failures table type = 7 , errorcode = -2 , date >= '2010-01-01'  group date  order date 

which returns total failures (all of happened on busy dates):

date       failures ---------- ----------- 2010-09-02 29 2010-10-04 16 2010-11-02 8 

is possible combine these single query return 1 result?

e.g.:

date       total       failures ---------- ----------- ----------- 2010-01-05 9466 2010-02-02 8747 2010-03-02 9010 2010-04-06 7916 2010-05-05 9342 2010-06-02 8723 2010-07-02 7829 2010-08-03 8411 2010-09-02 7687         29 2010-10-04 7706         16 2010-11-02 8567         8 2010-12-02 7645 

;with basedata ( select        date,        count(*) total,        count(case when errorcode = -2 1 end)  failures table type = 7 , date >= '2010-01-01'  group date  ) select       date,      total,      failures,       cast(failures float)/total ratio basedata total > 5000  or failures > 0 order date 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -