PostgreSQL
 sql >> Base de données >  >> RDS >> PostgreSQL

Comment améliorer les performances des sous-requêtes ?

Vous pouvez essayer ci-dessous - en utilisant case when expression

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