gpt4 book ai didi

php - 如何在带有左连接的 mysql select 查询中使用 CASE?

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

select  r.email,
rc.cuisine_id,
rc.restaurant_id,
c.id as c_id ,
c.name as cus_name,
r.image,
r.web_address,
r.area,
rp.TypeId,
rp.PaymentStatus ,
rp.RestaurantId
from restaurant as r
left join restaurant_cuisine as rc on r.id=rc.restaurant_id
left join cuisine as c on rc.cuisine_id=c.id where c.status='1'

需要的案例陈述

CASE WHEN rp.TypeId = '1' 
THEN left join restaurant_payment as rp on r.id=rp.RestaurantId
WHEN rp.TypeId = '3'
THEN left join users as u on rp.RestaurantId=u.id
END

最佳答案

试试这个

select  r.email,
rc.cuisine_id,
rc.restaurant_id,
c.id as c_id ,
c.name as cus_name,
r.image,
r.web_address,
r.area,
rp.TypeId,
rp.PaymentStatus ,
rp.RestaurantId
from restaurant as r
left join restaurant_cuisine as rc on r.id=rc.restaurant_id
left join cuisine as c on rc.cuisine_id=c.id where c.status='1' and
rp.TypeId = CASE
WHEN rp.TypeId = '1'
THEN left join restaurant_payment as rp on r.id=rp.RestaurantId
WHEN rp.TypeId = '3'
THEN left join users as u on rp.RestaurantId=u.id
END

关于php - 如何在带有左连接的 mysql select 查询中使用 CASE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27792177/

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