SQL交叉查询
类别: 数据库教程
sql:
select gwlb, count(case when (year(getdate())-year(rybirthday)) between 20 and 30 then rygh end) as \'20-30\',
count(case when (year(getdate())-year(rybirthday)) between 30 and 40 then rygh end) as \'30-40\',
count(case when (year(getdate())-year(rybirthday)) between 40 and 50 then rygh end) as \'40-50\',
count(case when (year(getdate())-year(rybirthday)) between 50 and 60 then rygh end) as \'50-60\',
count(case when (year(getdate())-year(rybirthday)) between 60 and 70 then rygh end) as \'60-70\'
from t_ry
group by gwlb
select gwlb, count(case when (year(getdate())-year(rybirthday)) between 20 and 30 then rygh end) as \'20-30\',
count(case when (year(getdate())-year(rybirthday)) between 30 and 40 then rygh end) as \'30-40\',
count(case when (year(getdate())-year(rybirthday)) between 40 and 50 then rygh end) as \'40-50\',
count(case when (year(getdate())-year(rybirthday)) between 50 and 60 then rygh end) as \'50-60\',
count(case when (year(getdate())-year(rybirthday)) between 60 and 70 then rygh end) as \'60-70\'
from t_ry
group by gwlb
- 上一篇: 计算指定年月的最后一天的自定义MYSQL函数
- 下一篇: 防范SQL注入式攻击
-= 资 源 教 程 =-
文 章 搜 索