我们都知道SQL中适用case when then来转化数据库中的信息
比如 select (case sex when 0 then ‘男‘ else ‘女‘ end) AS sex from studentInfo
那么在集合函数中它有什么用呢 ?
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
时间: 2024-12-14 07:47:06