相关疑难解决方法(0)

使用附加(不同)过滤器聚合列

这段代码按预期工作,但我很长而且令人毛骨悚然。

select p.name, p.played, w.won, l.lost from

(select users.name, count(games.name) as played
from users
inner join games on games.player_1_id = users.id
where games.winner_id > 0
group by users.name
union
select users.name, count(games.name) as played
from users
inner join games on games.player_2_id = users.id
where games.winner_id > 0
group by users.name) as p

inner join

(select users.name, count(games.name) as won
from users
inner join games on games.player_1_id = users.id
where games.winner_id = users.id
group by users.name
union
select users.name, count(games.name) as …
Run Code Online (Sandbox Code Playgroud)

sql postgresql aggregate-functions aggregate-filter

4
推荐指数
1
解决办法
1751
查看次数