ms sql multiple count queries 2 tables code example
Example: multiple count in sql
SELECT distributor_id,
count(*) AS Total,
sum(CASE WHEN inflevel = 'exec' THEN 1 ELSE 0 END) AS ExecCount,
sum(CASE WHEN inflevel = 'personal' THEN 1 ELSE 0 END) AS PersonalCount
FROM yourtable
GROUP BY distributor_id