Skip to content
Advertisement

Compare two Count() values sql

I have a table called “Takes” that has the following information. Takes(stud_id, class_id, sec_id, semester, year, grade)

I wanted to find the id’s of the students who took more classes in 2009 than in 2010 (in terms of number of classes. I have used the following code to extract the 2009 students total number of classes but not sure how to do the comparison

Advertisement

Answer

You can use conditional aggregation (CASE WHEN inside an aggregation function) and a HAVING clause:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement