SELECT A.ClassName, isnull(B. StudentCount, 0) as StudentCount
FROM (
SELECT DISTINCT ClassName
FROM
StudentMaster
) A
LEFT JOIN (
SELECT
ClassName, COUNT(*) AS StudentCount
FROM
StudentMaster
where (CreatedDate between Getdate()-1 and Getdate())
GROUP BY ClassName
) B
ON A. ClassName = B. ClassName
The above SQL Query will help you to get the
SQL count(*) and group by including zero
Make a query Count() return 0 instead of empty
Return 0 when result is empty
Make a query Count() return 0 instead of empty in group by
No comments:
Post a Comment