gpt4 book ai didi

php - 垂直连接两个sql语句

转载 作者:行者123 更新时间:2023-11-29 20:12:09 25 4
gpt4 key购买 nike

我想将以下两个sql语句连接成一个,这样我就有总共23行(第一个sql有23行,第二个sql有20行,这20行中每个sql中都有唯一的字段位置)与h3dac值第一个 sql 和第二个 sql 出现在列中。

请问有什么解决办法吗?

$sql_u1="select * from (select location1.location as locs, location1.elevation as elvn,location1.group as groups, shiftdata.location as loc1,  shiftdata.date,  shiftdata.shift,  shiftdata.h3dac as h3dac1 from location1 inner join shiftdata on location1.location=shiftdata.location where shiftdata.unit= 1 ORDER BY shiftdata.date desc, shiftdata.shift desc, location1.loc_id limit 23) as a left JOIN  (select location as loc1, date as date2, shift as shift2, h3dac as h3dac2  from shiftdata where unit= 1 ORDER BY date desc, shift desc limit 23 offset 23) as b on a.locs=b.loc1 left join (select location as loc3, date as date3, shift as shift3, h3dac as h3dac3 from shiftdata where unit= 1 ORDER BY date desc, shift desc limit 23 offset 46) as c on a.locs=c.loc3";

$sql_u2="select * from (select location2.location as locs,location2.elevation as elvn, location2.group as groups, shiftdata.location as loc1, shiftdata.date, shiftdata.shift, shiftdata.h3dac as h3dac1 from location2 inner join shiftdata on location2.location=shiftdata.location where shiftdata.unit= 2 ORDER BY shiftdata.date desc, shiftdata.shift desc, location2.loc_id limit 20) as a left JOIN (select location as loc1, date as date2, shift as shift2, h3dac as h3dac2 from shiftdata where unit= 2 ORDER BY date desc, shift desc limit 20 offset 20) as b on a.locs=b.loc1 left join (select location as loc3, date as date3, shift as shift3, h3dac as h3dac3 from shiftdata where unit= 2 ORDER BY date desc, shift desc limit 20 offset 40) as c on a.locs=c.loc3";

最佳答案

$sql ="select * from (sel....
union
select * from (sel....

您可以使用联合运算,它会返回没有重复的结果。

关于php - 垂直连接两个sql语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40015390/

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