gpt4 book ai didi

mysql - 在 1 个表中组合 2 个 SQL 查询

转载 作者:可可西里 更新时间:2023-11-01 08:45:34 24 4
gpt4 key购买 nike

我有 2 个查询:

查询 1:

SELECT w2.Avis,w2.Cde_Sap,w2.Don_Ordre,w2.PN_in ,w2.SN_in,w2.DATE2,w2.Statut_Cde,client.Zone
FROM w2
INNER JOIN client
ON w2.Don_Ordre = client.Client
WHERE client.Zone='CLR'
SORT BY w2.Avis ;

查询 2:

SELECT w3.Avis,w3.Cde_Sap,w3.Don_Ordre,w3.PN_in , w3.SN_in,w3.DATE2,w3.Statut_Cde,client.Zone
FROM w3
INNER JOIN client
ON w3.Don_Ordre = client.Client
WHERE client.Zone='CLR'
SORT BY w3.Avis;

我想在 1 Page 和 SORT BY Avis 中显示这两个查询。它不工作。

最佳答案

UNION ALL,在派生表中。 ORDER BY 结果:

select * from
(
SELECT w2.Avis as Avis,w2.Cde_Sap,w2.Don_Ordre,w2.PN_in ,w2.SN_in,w2.DATE2,w2.Statut_Cde,client.Zone
FROM w2
INNER JOIN client
ON w2.Don_Ordre = client.Client
WHERE client.Zone='CLR'

UNION ALL

SELECT w3.Avis,w3.Cde_Sap,w3.Don_Ordre,w3.PN_in , w3.SN_in,w3.DATE2,w3.Statut_Cde,client.Zone
FROM w3
INNER JOIN client
ON w3.Don_Ordre = client.Client
WHERE client.Zone='CLR'
) dt
order by avis

或者:

SELECT w2.Avis,w2.Cde_Sap,w2.Don_Ordre,w2.PN_in,w2.SN_in,w2.DATE2,w2.Statut_Cde,client.Zone
FROM (select * from w2
UNION ALL
select * from w3) as w2
INNER JOIN client
ON w2.Don_Ordre = client.Client
WHERE client.Zone='CLR'
SORT BY w2.Avis ;

关于mysql - 在 1 个表中组合 2 个 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30321661/

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