Following is my table schema.
Channel listing table:
CHAN_NUMBER CHAN_NAME CHAN_TYPE
----------- -----------------------------------
1 MTV Music
2 ESPN Sports
3 TNT Movies
4 Fox Movies
5 Fox Sports
customer survey table:
SURV_ID SURV_DATE SURV_FAV_CHAN CUST_NUMBER
---------- --------- ------------- -----------
1 25-NOV-12 1 2
2 24-NOV-12 2 1
3 24-NOV-12 3 3
4 24-NOV-12 4 4
5 24-NOV-12 5 5
6 24-NOV-12 1 6
7 24-NOV-12 2 7
8 24-NOV-12 3 8
9 24-NOV-12 4 9
10 24-NOV-12 5 10
11 24-NOV-12 1 11
I have these two tables that I need to generate a report that lists every channel and a count of how many customers have selected that channel as their favorite.
On oracle database I got up to the point where I am generating a count of each time a channel was selected as a favorite from the SURVEY table. But I can’t figure out how to join them to create a list of channels displaying the channel number, the name and the count of customers who chose it as their favorite.
-- my channel table query
SELECT CHAN_NUMBER, CHAN_NAME FROM CHANNEL;
-- here is how I'm generating the couNt
SELECT COUNT(SURV_FAV_CHAN) FROM SURVEY
GROUP BY SURV_FAV_CHAN HAVING COUNT(SURV_FAV_CHAN) > 1;
ANY HELP WOULD BE AWESOME.
You can try something like this:
And you may want to use SUM(SRV.SURV_FAV_CHAN) if you really need the total amount of customers if I understand you question correctly