sql-分组

sql分组——group by和case when

case when 有两种用法,等值查询和非等值查询。

`等值查询

select
case sex
when 1 then 'male'
when 2 then 'female'
else 'mixed'
end as sexual,sex
from tbl
select
case
when price>100 then 'expensive'
when price<=100 then 'cheap'
else '异常值'
end as price,价格分类
from tbl`
image

使用group by和case when 的两个例子

image

image

详细查看:
https://blog.csdn.net/WuLex/article/details/115055979?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-1-115055979-blog-106771313.t0_edu_mix&spm=1001.2101.3001.4242.2&utm_relevant_index=4

posted @ 2022-10-19 11:21  苍白之躯  阅读(57)  评论(0)    收藏  举报