刚入手公司项目,需要添加一个功能,用到了SQL的case when以及concat
SELECT eve.cc, eve.sc, case concat(cc,sc) WHEN ‘00‘ THEN ‘‘ WHEN ‘10‘ THEN ‘得意先‘ WHEN ‘01‘ THEN ‘仕入先‘ WHEN ‘11‘ THEN ‘得意先/仕入先‘ ELSE ‘‘ END as client_supplier_class FROM ( SELECT bd0.id, bd0.created, bd0.creator, bd0.modified, bd0.modifier, bd0.layout_id, bd0.app_id, bd0.parent_id, bd0.revision, bd0.rev_ctrl_id, bd0.owner, bd0.owned_org, ct0.client_cd, bd0.name, ct0.client_charge_select, usr.so_usr_furigana, ct0.client_charge_cd, ct0.official_name, ct0.pronunciation, ct0.zip_cd, ct0.address_1, ct0.address_2, ct0.tel, ct0.tel2, ct0.fax, ct0.fax2, ct0.lower_limit_time, ct0.lower_limit_time_unit, ct0.upper_limit_time, ct0.upper_limit_time_unit, ct0.valid_start_date, ct0.valid_end_date, ct0.client_class as cc, ct0.supplier_class as sc FROM basedataset bd0 LEFT JOIN sys_client_mst ct0 ON bd0.id::text = ct0.id::text LEFT JOIN ( SELECT v_user_all.id, v_user_all.furigana AS so_usr_furigana FROM v_user_all) usr ON usr.id::text = ct0.client_charge_select::text WHERE bd0.layout_id::text = ‘sys_client_mst‘::text) eve;
原文地址:https://www.cnblogs.com/sharysea/p/10880666.html
时间: 2024-10-07 05:12:22