The code snippet looks like this
(select count)
union
(select count)
union
(select count)
union
(select count)
union
(select count)
And the output is:
Count
291
3563
44
1
246
8123.
Is there a way I can add row labels? For instance, I would like the end output to be:
Col1. Col2.
‘Current Revenue’ 291
‘Current Sales’ 3563
And so forth. Is there a fastest/cleanest way to do this?
Thank you!
I tried doing a with and as CTE.
You can add a string literal to each query.
Side note: since you want to remove duplicates (and with those labels, presumably, there should be no duplicates), you can use union all
instead of union
for a slightly better performance:
SELECT 'Current Revenue', COUNT(*)
FROM revenue
WHERE ....
UNION ALL
SELECT 'Current Sales', COUNT(*)
FROM sales
WHERE ...
-- And so on