Count in sequential order
Hey you guys I have a question -
I asked before but don't think I explained my self correctly so trying again.
I have a data set that has a list of id's and with those id's are a list
of categories (so each id may have many categories). I want to search a
list of categories and see how many different id's are within that
category (count) but once a id is counted in one category it will not be
counted in another.
Example: (Suck at examples so this is random)
ID Category
1 Gas Station
1 Convenience Store
1 Barber
2 Day Care
2 Gas station
3 Convenience Store
3 Golf Range
So if I am doing a search of counts on gas station and convenience store
(in that order) Gas Station will get a count of 2 (For id 1&2) and then
Convenience store will get a count of 1 (id 3).
Currently my query looks like:
select category,distinct(id) from TABLE
where id in ('Gas Station','Convenience Store')
group by category
and It will give me
Gas Station -2
Convenience Store -2
** not what I want
No comments:
Post a Comment