sql - How can we merge the results of two queries have group by and two conditions -


i have these 2 tables: (games)

games table

and (rounds) table:

rounds table

i game id's, there round count, , count of how many rounds player1 wins. created 2 sql queries this:

queries , results

but want results in 1 table. how can combine results this: enter image description here

you can use conditional aggregation:

select game_id, count(*) roundscount,         count(case when winner = player1_id 1 end) p1winscount    games g inner join rounds r on g.id = r.game_id group game_id 

demo here


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -