Hi mahesh213,
Check the Value column with IS NOT NULL.
Refer below query.
SQL
DECLARE @Test AS TABLE(Id INT,[Name] VARCHAR(10),[Value] INT,Flag CHAR(1))
INSERT INTO @Test VALUES(1,'a',19,'Y')
INSERT INTO @Test VALUES(2,'b',30,'N')
INSERT INTO @Test VALUES(3,'c',50,'Y')
INSERT INTO @Test VALUES(4,'d',NULL,'Y')
INSERT INTO @Test VALUES(5,'e',NULL,'N')
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) Id,
COUNT(*) 'Count',Flag
FROM @Test
WHERE [Value] IS NOT NULL
GROUP BY Flag
ORDER BY Flag DESC
Output
Id |
Count |
Flag |
1 |
2 |
Y |
2 |
1 |
N |