I have a query in SQL Server which gives me the count of policies according to AGE and SEX as mentioned below.
SELECT
PLYMMRAGE as AGE,
MMRSEX as SEX,
COUNT(PLYNO) AS POLICYCOUNT
FROM
ADMGMPLYMSR
GROUP BY
PLYMMRAGE, MMRSEX
ORDER BY
MMRSEX DESC, PLYMMRAGE
Output of this query is:
AGE SEX POLICYCOUNT
------------------------
2 M 10
4 M 9
5 M 6
8 M 0
1 F 4
2 F 6
4 F 0
But I want that even if the age is not present the row should display for all ages with policy count as 0 till age 10.
AGE SEX POLICYCOUNT
-------------------------
1 M 0
2 M 10
3 M 0
4 M 9
5 M 6
6 M 0
7 M 0
8 M 0
9 M 0
10 M 0
1 F 4
2 F 6
4 F 0
and so on.
How can I insert the data with zero count if the age for that row is not present? Even if using procedure is fine