Skip to content
Advertisement

Combine SQL queries with different WHERE causes

I have written a database with game stats, featuring winner, loser, and money won. I’m now trying to make stats for it.

See database here

I’m trying to make stats for these games, etc number of wins/losses for player, and money lost and money won.

Till now I have found three queries to achieve this.

The problem is, it’s in no way effective using three queries, so I’m trying to reduce this to one. Does anyone have any idea what I can do?

Advertisement

Answer

Use conditional aggregation as follows:

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