Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
好的,所以我有 2 张桌子
第一个被调用msg,另一个是msg_t
msg
msg_t
msg(id, send_type, ..) msg_t(id, msg_id, send_time)
我要做的是获取msgsend_type = 1 的所有行
并计算msg_t每个条目msg并按月分组
我怎样才能做到这一点?
SELECT a.ID, MONTHNAME(b.send_time), COUNT(b.msg_id) totalCount FROM msg a LEFT JOIN msg_t b ON a.ID = b.msg_id WHERE a.send_type = 1 GROUP BY a.ID, MONTH(b.send_time)
通过 using ,对于表上没有记录LEFT JOIN的将显示零值msg.IDmsg_t
LEFT JOIN
msg.ID
SELECT m.id, MONTH(send_time) COUNT(t.*) FROM msg m INNER JOIN msg_t t ON m.id = t.msg_id WHERE m.send_type = 1 GROUP BY m.id, MONTH(send_time)