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 @   苍白之躯  阅读(50)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示