【发布时间】:2013-01-01 11:51:16
【问题描述】:
我有一个表,有一个名为 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
我是否可以在不执行多个查询且不执行子查询的情况下执行此操作?
【问题讨论】:
标签: mysql select join count group-by