gpt4 book ai didi

php - MySQL从表中选择数据并内连接来自另外两个相同表的所有选择

转载 作者:行者123 更新时间:2023-11-29 23:18:38 24 4
gpt4 key购买 nike

首先,我有两个表,我使用以下查询进行连接

SELECT o5.id AS id, DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date, o5.ime_prezime AS name, o5.adresa AS address, o5.mesto AS city, o5.embg AS mb, o5.serial_no AS ticket, o1.uplata AS uplata, o5.pdd AS danok, o5.isplata AS neto_dobivka, o1.iznos_isplaten AS bruto_dobivka FROM o5 INNER JOIN o1 ON o5.serial_no = o1.serial_no WHERE o1.transaction_type = 'I' 

而且它的工作正常现在我需要从另一个表“o1_payout_storno”中选择数据,该表与o1相同我需要从 o5INNER JOIN 中选择数据,并从 o1o1_payout_storno< 中选择 UNION ALL/.

最佳答案

它应该像这样简单明了:

SELECT 
o5.id AS id,
DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date,
o5.ime_prezime AS name,
o5.adresa AS address,
o5.mesto AS city,
o5.embg AS mb,
o5.serial_no AS ticket,
o1.uplata AS uplata,
o5.pdd AS danok,
o5.isplata AS neto_dobivka,
o1.iznos_isplaten AS bruto_dobivka
FROM o5
INNER JOIN o1 ON o5.serial_no = o1.serial_no
WHERE o1.transaction_type = 'I'
UNION ALL
SELECT
o5.id AS id,
DATE_FORMAT(o5.vreme_isplata, '%d.%m.%Y') AS payed_date,
o5.ime_prezime AS name,
o5.adresa AS address,
o5.mesto AS city,
o5.embg AS mb,
o5.serial_no AS ticket,
op.uplata AS uplata,
o5.pdd AS danok,
o5.isplata AS neto_dobivka,
op.iznos_isplaten AS bruto_dobivka
FROM o5
INNER JOIN o1_payout_storno AS op ON op.serial_no = o5.serial_no

关于php - MySQL从表中选择数据并内连接来自另外两个相同表的所有选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27546949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com