Quantcast
Channel: Questions in topic: "distinct"
Viewing all articles
Browse latest Browse all 38

Distinct sums of case statements

$
0
0
This has stumped me. Not sure how to get a distinct sum inside a case statement. Here's a sample of my data in the two fields (I'm actually doing this for a year but just 2 months here for easier reading): empid date 132 7/1/2012 143 7/1/2012 154 7/2/2012 154 7/3/2012 123 8/1/2012 197 8/1/2012 197 8/2/2012 187 8/3/2012 I need a count of each month in a column but each emp needs to count as one, like this: Jul11 Aug11 3 3 but instead I get 4 and 4. Here is my code SELECT sum(case when month(hist_date)='07' and year(hist_date) = '2011' then 1 else 0 end) as Jul11, sum(case when month(hist_date)='08' and year(hist_date) = '2011' then 1 else 0 end) as Aug11 FROM empjobst I've tried putting the word distinct in between Select and sum but that made it a 1 and 1. Any help would be much appreciated. Cyndi

Viewing all articles
Browse latest Browse all 38

Trending Articles