PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Come migliorare le prestazioni delle sottoquery?

Puoi provare di seguito, utilizzando case when espressione

select "uid", "username", count(case when state = 'finished' then id end) as games_hosted 
from "users" inner join "games" 
on "games"."user_uid" = "users"."uid" 
where "games"."state" in ('published', 'finished') and "username" < 'HariShankar' 
group by "uid", "username"
order by "username" desc 
limit 10