My goal is to count all the distinct nodeIDs grouped by classification and date applied. I have to use distinct NodeIDs because there are multiple rows of the same NodeID for the same date with the same ClassificationID. Not sure why this is but it is how the data appears in the table.
I run the following SQL and get the following results:
Select ClassificationID, count(DISTINCT NodeID)
from ADVClassApplied adv with (NOLOCK)
where DateApplied between '06-01-2016' and '07-01-2016' and ClassificationID in (106332120, 167084905, 288477278)
group by ClassificationID
Order By 1, 2
106332120 24245 167084905 632 288477278 5446
I add my Date field and run the adjusted SQL and get the following results:
Select ClassificationID, left(dateapplied,11) as Date, count(DISTINCT NodeID)
from ADVClassApplied adv with (NOLOCK)
where DateApplied between '06-01-2016' and '07-01-2016' and ClassificationID in (106332120, 167084905, 288477278)
group by ClassificationID, left(dateapplied,11)
Order By 1, 2
106332120 Jun 3 2016 1663 106332120 Jun 7 2016 22915 106332120 Jun 8 2016 250 24828 167084905 Jun 3 2016 50 167084905 Jun 7 2016 599 167084905 Jun 8 2016 5 644 288477278 Jun 7 2016 5353 288477278 Jun 8 2016 93 5446
I did the totalling by hand but you can see that for two of the three ClassificationIDs the total is different. I know this has to do with the way I am doing my group bys. But I can't figure out what is wrong. I have tried changing the order of the group bys and that didn't make a difference. I just have to make sure the numbers are right here and I am fairly certain they are not.