當前位置:首頁 > IT技術(shù) > 數(shù)據(jù)庫 > 正文

mysql中sql腳本對case when then的用法大全
2021-09-14 09:14:45

在mysql腳本中,case when then 是對列的枚舉進行翻譯為可讀性好的文字

例如:性別這列 1 代表男? 2代表女

case when xingbie='1' then '男'

when xingbie='2' then '女' end as 性別

--tips: 我們知道這列的枚舉值是什么,并可以對枚舉值一一翻譯,超過10個以上就不建議使用case when then了

?

--我自己的腳本可以供大家參考

SELECT t.latn_id as XXX,t.CUST_ORDER_ID as XXX,t.upload_state XXX,
case when t.STATUS_CD='101300' then 'XXX'
when t.STATUS_CD='101200' then 'XXX'
when t.STATUS_CD='201700' then 'XXX'
when t.STATUS_CD='201300' then 'XXX'
when t.STATUS_CD='301100' then 'XXX' else 'XXX'
end as XXX,
t.CREATE_DATE as XXX
FROM customer_order t,
order_attr t1
where t.CUST_ORDER_ID=t1.CUST_ORDER_ID
and t1.ATTR_ID='5050'
and t.CREATE_DATE >= '2021-09-13 08:00:00'

本文摘自 :https://www.cnblogs.com/

開通會員,享受整站包年服務(wù)立即開通 >