Skip to content
Advertisement

get both the total count of enrollments and the count of sigtrack enrollments in one query

I have a table with following schema:

Column      Type   Description
user_id     INT    A unique identifier for a student.
session_id  INT    A  unique identifier for a course.
is_sigtrack CHAR   Identifies whether the enrollment is paid (sigtrack) or free. Values 'Y' or 'N'

I am trying to get both the total count of enrollments and the count of sigtrack enrollments in one query?

Advertisement

Answer

You could use conditional aggregation and count

select count(*) count_enroll, sum(case when is_sigtrack  ='Y' THEN 1 ELSE 0 END ) count_sigtrack
from my_table
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement