03-29-2017 09:20 AM
My variables: ID, year, drinks(beer or wine).
I want to count distinct ID by the drinks variable: only count the ID-numbers who only drank beer and those who only drank wine. If a person drank both, they should not be in any count.
create tables want as
select year, drinks, count(distinct ID)
group by year, drinks
This only count distinct within each drink-type: if a person has more than one beer he is only in the count once, but if he also had wine he is also in the count for wine.
Hope someone can help me with my problem!!
03-29-2017 09:51 AM
I think this is hard to achieve in a single (non nested) SQL step.
What about if a person drinks beer year 1, and wine year 2?