I need to do a couple of queries that should be pretty simple, but it’s been a long time since I’ve used SQL, and lord knows I wasn’t any good at it even then…
So let’s say that I ran a survey asking people how much they liked some different bands, then dumped the data into SQL. I could end up with a table (actually a view) kinda like this:
Subject Occupation Band AttitudeTowardBand
John Musician Beatles Love them
Paul Musician Beatles Love them
George Musician Beatles Tired of them
Ringo Musician Beatles Love them
Groucho Actor Beatles Hate them
Harpo Musician Beatles Tired of them
Chico Actor Beatles Hate them
Zeppo Actor Beatles Love them
John Musician Stones Hate them
Paul Musician Stones Love them
George Musician Stones Tired of them
Ringo Musician Stones Love them
Groucho Actor Stones Hate them
Harpo Musician Stones Tired of them
Chico Actor Stones Hate them
Zeppo Actor Stones Love them
So I want to be able to run queries that will give me something like the following (for a given band, count the number of responses per attitude regardless of occupation):
Band Count Attitude
Beatles 4 Love them
Beatles 2 Tired of them
Beatles 2 Hate them
Or this (for a given band, count the number of responses per attitude and occupation):
Band Occupation Count Attitude
Beatles Musician 3 Love them
Beatles Musician 2 Tired of them
Beatles Actor 1 Love them
Beatles Actor 2 Hate them
Or this (for a given attitude, count the number of responses per band regardless of occupation):
Attitude Count Band
Love them 4 Beatles
Love them 3 Stones
Or this (for a given attitude, count the number of responses per occupation and band):
Attitude Occupation Count Band
Love them Musician 3 Beatles
Love them Actor 1 Beatles
Any recommendations on how I could go about doing this?