mysql 如何同时查询3个表

mysql 如何同时查询3个表,第1张

如果a是唯一的话那就select table1.id,table2.id,table3.id from table1,table2,table3 where table1.a='12' and table1.a=table2.a and table2.a=table3.a

或者如果对下你给数据相同的话,可以用union 连接 在用一个标志位,区分三张表!

SELECT aaa.id, REPLACE(bbb.bcode, bbb.bcode, 'a') aa, REPLACE(ccc.ccode, ccc.ccode, 'b') bb, concat_ws( '', REPLACE(bbb.bcode, bbb.bcode, 'a'), REPLACE(ccc.ccode, ccc.ccode, 'b')) ab FROM a aaa left Join b bbb ON ( aaa.id = bbb.ida ) left Join c ccc ON ( aaa.id = ccc.idb ) ORDER BY aaa.id ASC

我专门建了跟你一模一样的表,测试过了,出来的结果也跟你要的一模一样。

你最想要的结果:

SELECT aaa.id, concat_ws( '', REPLACE(bbb.bcode, bbb.bcode, 'a'), REPLACE(ccc.ccode, ccc.ccode, 'b')) ab FROM a aaa left Join b bbb ON ( aaa.id = bbb.ida ) left Join c ccc ON ( aaa.id = ccc.idb ) ORDER BY aaa.id ASC

temp_instore 、 temp_outstore 、 temp_stock三张表,以temp_stock表数据为主,统计与mate_id、sd_price两个字段值在另外两张表中相等的记录,主要查询出mate_id、sd_price、(sd_quantity + os_quantity - is_quantity) as quantity

就是sd_price与os_price、is_price比较,三者相等按上述进行加减运算,若os_price或is_price与sd_price不等按零处理。


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

原文地址:https://54852.com/zaji/7610696.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存