SQL语句如下:
根据表中某个字段的值 来进行判断,分别查询B表或C表中的字段值。
purchase.psort_Id,
(case
when quote_type = ‘PC’ or quote_type = ‘TD’ THEN
(select purchase_title
from df_purchase_demand pd
where pd.ps_id = quot.master_id limit 1)
when quote_type = ‘IV’ then
(select inventory_Title
from df_inventory dv
where dv.ivt_id = quot.master_id limit 1)
end) as item_title
from df_quote quot
left join df_purchase_demand purchase on quot.master_id = purchase.ps_id
where 1 = 1
and quot.site_Id is not null
order by quot.create_time desc
版权声明:本文为guoxu775原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。