mysql 多表联合统计

发布网友 发布时间:2022-04-21 07:23

我来回答

3个回答

热心网友 时间:2022-05-01 23:44

SELECT m.user_id, b_total, c_total, d_total FROM a m, (SELECT user_id, COUNT(*) b_total FROM b GROUP BY user_id) n,
(SELECT user_id, COUNT(*) c_total FROM c GROUP BY user_id) j, (SELECT user_id, COUNT(*) d_total FROM d GROUP BY user_id) k,
WHERE m.user_id = n.user_id AND m.user_id = j.user_id AND m.user_id = k.user_id;

热心网友 时间:2022-05-02 01:02

select (b.b_total + c.c_total + d.d_total) as `sum` from a,b,c,d where a.user_id = b.user_id and b.user_id = c.user_id and c.user_id = d.user_id and d.user_id = a.user_id and a.user_id < 100

热心网友 时间:2022-05-02 02:36

select a.id,sum(b.datab),sum(c.datac),sum(d.datad) from a,b,c,d
where a.id=b.id(+)
and a.id=c.id(+)
and a.id=d.id(+)
group by a.id

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com