Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Gruppieren nach Null- und Nicht-Null-Werten

Sie können dies einfach per Case-Anweisung tun:

SELECT SUM(CASE WHEN FACEBOOKID IS NULL THEN 1 ELSE 0 END) AS NbUsers , 'NO' AS FACEBOOK
FROM USERTABLE
UNION ALL 
SELECT SUM(CASE WHEN FACEBOOKID IS NULL THEN 0 ELSE 1 END) AS NbUsers , 'YES' AS FACEBOOK
FROM USERTABLE