sqlgroup-bycountsumclause

How many elements in one column are linked to an element other column?


Consider I have two tables

Courses            Program
---------------------------
course_ID          program_id
course_title       program_name   
program_ID     

Now, I want to check no of courses(by course_id) offered by each program (program_id).


Solution

  • select c.program_id ,p.program_name, count(course_id)
    from courses c
    join Program p on c.Program_id =p.Program_id
    group by program_id,program_name