Skip to content
Advertisement

Count one column by considering another column

This is my Audit table:

I need to write 2 different queries and I have no idea how should I write them:

  1. How many invoices do have ONLY product 2 (+ Total price)?

  2. How many invoices do have diffrent products but product 2 as well (+ Total price)?

the result I want looks like this:

Advertisement

Answer

If I understand correctly, you can use two levels of aggregation:

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