Skip to content
Advertisement

Count and Group by 2 different columns SQL

I have below table and want to find out a count and group by that will show the number of times republic of ireland played a particular opponent regardless if they are the home team or away team

table

I want something that will show like the below

Thanks for help!

Advertisement

Answer

This is how I would do it — normalize the table with a UNION ALL and then group by and count


If you know that every record has ‘Republic of Ireland’ as one of the teams, then you don’t need to check if it exists only which is which like this:

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