Skip to content
Advertisement

How to get the count of 2 values in the same column, in the same table?

I have a dataset about chess games, and in the winner column there are only 2 values: ‘white’ and ‘black’. I want to show COUNT(winner) as WHITE_WINS and COUNT(winner) as BLACK_WINS. I tried inner joining the table by itself, however couldn’t get the correct SQL query to do the job. How can I get a table like:

Advertisement

Answer

Use conditional aggregation:

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