关于sql的case when用法简述
Posted sharysea
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于sql的case when用法简述相关的知识,希望对你有一定的参考价值。
刚入手公司项目,需要添加一个功能,用到了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;
以上是关于关于sql的case when用法简述的主要内容,如果未能解决你的问题,请参考以下文章
CASE WHEN 及 SELECT CASE WHEN的用法(写了一坨烂代码发现两条sql就完成了, 哎)