Skip to content
Advertisement

SQL Query – How to apply different conditions (Where clause?) to specific aggregated columns

I have a table (simplified example below) consisting of TEST(s), TESTPRICE per test and TESTSTATUS. I would like to be able to run a query that will result in two aggregated columns, one for pending revenue and one for started revenue per test group.

tblREQUEST

I can easily generate two seperate result tables by executing the following:

This results in two out put results like this:

enter image description here

enter image description here

However, I would prefer a single output result table like this:

Desired Output

Can anyone point me in the right direction here, advise on a technique I can read up on – I’ve tried a few different approaches (subqueries, etc.) but the closest I seem to get is a total sum for a given TESTSTATUS in all rows, or errors

Any help is appreciated

Advertisement

Answer

Using conditional aggregation, which in most databases looks like this:

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