我有一个表,其中有一列称为type
它包含两个单词之一,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
我是否可以在不执行多个查询且不执行子查询的情况下执行此操作?