gpt4 book ai didi

mysql 在同一查询中使用选定的变量

转载 作者:行者123 更新时间:2023-11-29 13:38:28 25 4
gpt4 key购买 nike

我有一个表“booking_summary”,它存储方法的类型(方法=空运或海运)。我必须根据方法列将该表与其他两个表之一连接起来。

如果方式是Air,则加入的表是booking_air,如果是sea,则加入的表是booking_sea。我不想在此特定页面上运行多个查询。

这是我最近的尝试,显然已经失败了。带有别名的 table_name 是我在同一查询中想要的表。

$sql = "select case when a.shipping_method = 'Sea' then 'booking_sea' else 'booking_air' end 'table_name',
case when a.user_id ='$active_id' then 'y' else 'no' end 'generate_access',
case when c.mbl is NULL then 'Pending' else c.mbl end 'mbl_status',
case when c.hbl is NULL then 'Pending' else c.hbl end 'hbl_status',
a.*,b.user_name
from booking_summary a
left join registered_users b
on a.user_id = b.user_id
left join table_name c
on a.id = c.id
where (a.user_id = '$active_id' or a.forwarder='$active_id')";

任何建议都会非常有帮助。谢谢

最佳答案

嗯,我不确定这是否会起作用,但是,无论如何......

$sql = "select case 
when a.user_id ='$active_id' then 'y'
else 'no' end 'generate_access',
if(a.shipping_method = 'Sea',
case when c.mbl is NULL then 'Pending' else c.mbl end,
case when d.mbl is NULL then 'Pending' else d.mbl end ) 'mbl_status',
if(a.shipping_method = 'Sea',
case when c.hbl is NULL then 'Pending' else c.hbl end,
case when d.hbl is NULL then 'Pending' else d.hbl end ) 'hbl_status',
a.*,b.user_name
from booking_summary a
left join registered_users b on a.user_id = b.user_id
left join booking_sea c on a.id = c.id
left join bookin_air d on a.id=d.id
where (a.user_id = '$active_id' or a.forwarder='$active_id')";

关于mysql 在同一查询中使用选定的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18444763/

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