|
Please be gentle! - this is my first post and I'm a total SQL novice thrown in at the deep end at work.
I need to output something like:
Name1 count#1 count#2 count#3 count#4
Name2 count#1 count#2 count#3 count#4
etc...
count#1 needs to be all the entries with a given "Name"
count#2 needs to be the subset of those that also has field#2 = value#1
count#3 needs to be the subset of those that also has field#2 = value#2
etc...
I can get something like:
SELECT
Name,
otherData
FROM
DBName
WHERE
field#3= value AND field#4 NOT IN ('valueA', 'valueB', 'valueC')
ORDER BY
Name
And that returns the subset I want to count, but as soon as I try replacing the "otherData" in the SELECT with:
count (when field#2=value#2 then 1 else 0 end) as count#1,
count (when field#2=value#3 then 1 else 0 end) as count#2,
count (when field#2=value#4 then 1 else 0 end) as count#3,
and adding this at the end:
GROUP BY
Name
Then I get totally silly counts.
I'm going round in circles trying to fix this, and no amount of web surfing is giving me any real clues. HELP!!!
|