wtuqi
3/19/2020 - 6:36 AM

结构语句

/*--------原表---------
id name counts flag
1  铅笔  3       0
2  钢笔  1       1
---------------------*/
select ID,name,
case flag when '0' then '出库' else '入库' end 
from input
/*--------显示--------
id name counts flag
1  铅笔  3     出库 
2  钢笔  1     入库
---------------------*/

--实例二
select b.id 工号,a.code 卡号,a.tp 类型,a.APtime 时间,
case when tp like '%上班' and stat=1 then '迟到'
when tp like '%下班' and stat=1 then '早退'  else '正常'end 
状态,b.tel 电话 from Attendance a,Tb_User b  where a.code=b.code
--实例三
select *,case  when 总得分>100 then  'A'  when 总得分<90 then 'C' else 'B' end  from grade