Skip to content
Advertisement

SQL select with two conditions

On a table like this, I want to know how many teams that have been visited X times and have medal Y. So far, I can count how many teams where visited X times.

With this, I know how many teams (it doesn’t matter which ones) where visited once, twice, three times, and so on… But now how do I know, for instance, from the ones that were visited once, how many have medal 1?

An expected result would be:

How many teams, that were visited three times, have medal 2?

The answer would give me 2 (because both teams 1 and 4 were).

Or how many teams, that were visited three times, have medal 3?

The answer would be 1 (because only team 4 was).

Should I use an inner join? Can I do it based on the query that I already have?

Advertisement

Answer

You can use the following. Here is the demo.

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