Bạn có thể thử bên dưới- sử dụng case when
biểu thức
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