I have to generate a report that displays the name of different locations and the number of times unique course offerings are offered in these locations. The report needs to only indicate the city and the no. of unique course offerings and be sorted by the highest number of unique offerings. The problem I have is the offering table has a composite primary key (offering begin date and course code)
I run this SQL query and it comes up with an error as you can't count multiple columns. But I am not sure how to split the count.
SELECT
offlocation AS city, COUNT(distinct offbegindate,crscode) as no. of unique course offerings
FROM
offering
GROUP BY offlocation
ORDER BY COUNT(distinct offbegindate,crscode) as no. of unique course offerings DESC;
Any help will be greatly appreciated.
Just minor adjustments, "Row types" for count distinct:
SELECT
offlocation AS city,
COUNT(distinct (offbegindate,crscode)) as no_of_unique_course_offerings
FROM
offering
GROUP BY offlocation
ORDER BY no_of_unique_course_offerings DESC;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With