CASE用法CASE WHEN condition1 THEN returnvalue1 &n
CASE用法
CASE
WHEN condition1 THEN returnvalue1
WHEN condition 2 THEN returnvalue2
WHEN condition 3 THEN returnvalue3
ELSE defaultreturnvalue
END
相当于if…else…else….
SELECT FName, FWeight,
(CASE
WHEN FWeight<40 THEN ‘瘦瘦'
WHEN FWeight>50 THEN ‘肥肥'
ELSE 'ok'
END)
as isnORMal
FROM T_Person
create table bs
(
bsname char(20),
bsflag char(20),
bstime datetime
)
insert bs values('火箭','胜','2008-01-10')
insert bs values('火箭','负','2008-01-11')
insert bs values('火箭','胜','2008-01-10')
insert bs values('公牛','负','2008-01-10')
insert bs values('公牛','胜','2008-01-11')
insert bs values('公牛','负','2008-01-10')
select * from bs
select bsname,胜=sum(case when bsflag= '胜' then 1 else 0 end),
负=sum(case when bsflag='负' then 1 else 0 end)
from bs group by bsname
--结束END--
本文标题: SqlServer系列笔记——case when 语句
本文链接: https://lsjlt.com/news/51289.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0