mysql count 多表联查问题

mysql count 多表联查问题,第1张

a right join d right join c====(a right join d) right join c

你的目的是找c表中能在a表找到对应值记录的数量找d表中能在a表找到对应值记录的数量

但是你最后一句的涵义是a表中能在d表和c表同时找到对应值的数量,此时count(c.p_rel_id)其实是你c表的数量,就是那个504的涵义,至于count(d.p_rel_id)为什么等于504 完全是凑巧~~~

select sum(cnt) from

(

select count(*) as cnt from tb_one where title like '%蜡笔小新%'

union all

select count(*) as cnt from tb_two where title like '%蜡笔小新%'

union all

select count(*) as cnt from tb_three where title like '%蜡笔小新%') t

这样不就可以么?


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8573723.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-18
下一篇 2023-04-18

发表评论

登录后才能评论

评论列表(0条)

保存