PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Wie kann die Leistung der Unterabfrage verbessert werden?

Sie können es unten versuchen - mit case when Ausdruck

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