MYSQL5下查询语句CASE WHEN 子查询的使用

SQL语句如下:

 

根据表中某个字段的值 来进行判断,分别查询B表或C表中的字段值。

select 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   

 

你可能感兴趣的:(MYSQL5下查询语句CASE WHEN 子查询的使用)