Skip to content
Advertisement

How to add ‘all’ CASE when group by CASES in SQL

I have a query like this:

Which gives the result: query result

How can I add a row for ‘all’ requests in CASES? If we add a when sp.provider='prv1' with no more detailed condition then all cases become one ‘all’ case because and other cases are ignored.

Advertisement

Answer

You can’t do that inside the CASE, as it behaves like a series of IF.

You need to compute the total separately and append it using UNION or delegate the total calculation to whatever tool uses those data.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement