gpt4 book ai didi

sql - 如何离开连接表并保持顺序?

转载 作者:行者123 更新时间:2023-12-04 10:30:15 25 4
gpt4 key购买 nike

我试图像这样加入这两个表:

select 
T2.*
from
(SELECT DISTINCT DésignationBDC2 FROM pdc2 where BDC3 like '%01|06|02%') AS T1
LEFT JOIN (select DésignationBDC2, COULEUR from pdc2 where Id=60) AS T2 ON T1.DésignationBDC2 = T2.DésignationBDC2

这些表是:

enter image description here

enter image description here

但是,我明白了:

enter image description here

正如您所看到的,“DésignationBDC2”的顺序从第一个表中丢失了。
我怎样才能避免这种情况?

最佳答案

你不需要使用子查询你可以做 left join :

SELECT DISTINCT C2.DésignationBDC2, C22.COULEUR  
FROM pdc2 AS C2 LEFT JOIN
pdc2 AS C22
ON C22.DésignationBDC2 = C2.DésignationBDC2 AND C22.ID = 60
WHERE P2.BDC3 like '%01|06|02%'
ORDER BY C2.DésignationBDC2;

关于sql - 如何离开连接表并保持顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60448342/

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