Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqlblaze
Starting Member
1 Post |
Posted - 2010-10-12 : 19:41:29
|
| Help.I am trying to perform 2 counts on the same set of data, but the results I get don't group the data by month. I need the count to seperate it by discards and total, but it just gives me the same total for all months. See example below. ThanksSQL CODE:SELECT billing.`Month Closed`,(Select count(billing.Group) FROM billing WHERE billing.Group LIKE '%discard%') AS DISCARD, (Select count(billing.Group) FROM billing) AS TOTALFROM billingGROUP BY billing.`Month Closed`;RESULTS: NOT GROUPED BY MONTHMONTH CLOSED DISCARD TOTAL2010 04 Apr 400 224272010 05 May 400 224272010 07 Jul 400 224272010 08 Aug 400 224272010 09 Sep 400 22427 |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2010-10-12 : 21:50:26
|
| [code]select billing.'Month Closed', count(case when billing.Group like '%discard%' then billing.Group end) as DISCARD, count(billing.Group) as TOTALfrom billinggroup by billing.'Month Closed';[/code] |
 |
|
|
|
|
|