之前在面试的时候就遇到过关于case...when...then...的使用,当时只是为了应付面试,没有深入研究。但是今天在做公司项目的时候遇到这个问题,其实case。。。when。。。then的使用很简单。
eg:
select
prodid, prodname,proddesc,prodtype,
(case when state=0 then '有效' ELSE '无效' end)as state,
effdate,expdate,CAST(optionminnum AS CHAR(8)) as optionminnum,
CAST(optionmaxnum AS CHAR(8)) as optionmaxnum,repeatflag,sptime,spoptrid,optrid,opttime,remark
from tb_ac_prodinfo
这段sql语句其实很简单,就是查询语句,当查询到的state是0时,则显示在页面上的是有效,如果state=1,则显示在页面上的是无效。