SQL集合函数中利用case when then 技巧

我们都知道SQL中适用case when then来转化数据库中的信息

比如  select (case sex when 0 then '男' else '女' end) AS sex  from studentInfo

那么在集合函数中它有什么用呢 ?

SQL集合函数中利用case when then 技巧

SQL集合函数中利用case when then 技巧

SQL集合函数中利用case when then 技巧

SELECT sex FROM student

SELECT sex,COUNT(*) AS num FROM student GROUP BY sex

SELECT sex,province,COUNT(*) AS num FROM student GROUP BY sex,province
SELECT sex,province,COUNT(province) AS num FROM student GROUP BY sex,province SELECT sex,province,COUNT(CASE province WHEN '浙江省' THEN '浙江省' ELSE province END ) AS num FROM student GROUP BY sex SELECT sex,COUNT(CASE province WHEN '江西省' THEN '江西省' END) AS 江西省 ,COUNT(CASE province WHEN '广东省' THEN '广东省' END) AS 广东省,
COUNT(CASE province WHEN '浙江省' THEN '浙江省' END) AS 浙江省 FROM student GROUP BY sex
上一篇:个人永久性免费-Excel催化剂功能第46波-区域集合函数,超乎所求所想


下一篇:JavaScript(第二十七天)【错误处理与调试】