Skip to content
Advertisement

Selecting cities that have a combination of products in SQL

I have the following dataset, that have the prices for many products and cities:

What I want is to have the average price for each month and each city but it has to follow a rule, that it should have the combination of certain products. Let’s say that the product should be A and B strictly, then the expected table is:

As you see, in this case LISBO doesn’t appear in 2019-07 because the condition “A and B” strictly doesn’t hold.

I have tried this code:

But I don’t know how to apply the condition. Please, could you help me with this question? Thank you in advance.

Advertisement

Answer

if you need in rows then you need to group by product as well:

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