type
2 つの単語のうちの 1 つを保持するという列を持つテーブルがあるupvote
かdownvote
、a.question_id でグループ化し、それぞれのカウントを持つ 2 つの列を取得します。
select a.*, u.* from answers a
left join users u using(user_id)
left join vote_history v using(answer_id)
where a.question_id = 4 and deleted < 4
group by v.question_id
order by votes desc
オプトの例
ColumnA | ColumnB | upvotes | downvotes
---------+----------+---------+----------
record1A | record2B | 3 | 2
record2A | record2B | 2 | 5
複数のクエリを実行せずに、サブクエリを実行せずにこれを行うことは可能ですか?