What is the most elegant/efficient way to check multiple different count()'s with different conditions within the same statement? Given the syntax of SQL, it appears that I can only have one count() statement with each set of WHERE/HAVING conditionals within my query. Therefore, to utilize a different set of WHERE/HAVING conditionals, it seems this second count(*) needs to be in a different select statement. Is the best way to put this into the same result set to UNION them? Is there any alternative?
Ideally I could do something like:
SELECT count(*) as First, count(*) as Second
FROM table
WHERE --conditionals for First
AND
--conditionals for Second
But I think this is impossible. Is the only way to do it to UNION two separate queries?
SELECT COUNT(CASE WHEN //conditionals THEN 1 END), COUNT(CASE WHEN //conditionals THEN 1 END) as Second FROM table;COUNTis implemented asSUM(CASE WHEN ... 1 ELSE 0 END).SUM+CASE) with window frames (OVER).