I have a request that looks like
SELECT ju.name,
COUNT(DISTINCT p.value) AS nproblems
FROM
JOIN <thing> ju ON <whatever>
WHERE <condition 1>
AND <condition 2>
AND <condition 3>
GROUP BY ju.name
ORDER BY nproblems DESC
This is good, and gives me a set of results with names and values. But I really care about the number of problems without the WHERE clause, and then with condition 1, then conditions 1 + 2, then conditions 1 + 2 + 3. I would like to write
SELECT ju.name,
COUNT(DISTINCT p.value WHERE <condition 1>) foo,
COUNT(DISTINCT p.value WHERE <condition 2>) bar,
...
but unfortunately I can’t. Is there a good way to do this?
source
share