2个回答
展开全部
--不知道你要的是不是这样的结果
Create table T
(
籍贯 varchar(10) ,性别 varchar(2), 生日 varchar(10)
)
insert into t values('四川' , '男', '19890627')
insert into t values('新疆' , '男', '19930711')
insert into t values('河南' , '男', '19890623')
insert into t values('四川' , '女', '19880512')
insert into t values('新疆' , '男', '19950425')
insert into t values('河南' , '女', '19800304')
Select 籍贯,性别 ,
Sum(Case When 年龄 <=20 Then 1 Else 0 End) As [0-20岁(人)],
Sum(Case When 年龄 Between 21 And 40 Then 1 Else 0 End) As [21-40岁(人)],
Sum(Case When 年龄 Between 41 And 60 Then 1 Else 0 End) As [41-60岁(人)],
Sum(Case When 年龄 >=61 Then 1 Else 0 End) As [60岁以上(人)]
From
(
Select *, Year(GETDATE())- Year(convert(Datetime,生日)) As 年龄
From t
) s
Group By 籍贯,性别
with rollup
TableDI
2024-07-18 广告
2024-07-18 广告
仅需3步!不写公式自动完成Excel vlookup表格匹配!Excel在线免,vlookup工具,点击26步自动完成表格匹配,无需手写公式,免费使用!...
点击进入详情页
本回答由TableDI提供
展开全部
select
province,
case when birthday>'20150507' and birthday<='19950507' then 1 else null end,
case when birthday>'时间段' and birthday<='时间段' then 1 else null end
from 表
group by province
province,
case when birthday>'20150507' and birthday<='19950507' then 1 else null end,
case when birthday>'时间段' and birthday<='时间段' then 1 else null end
from 表
group by province
更多追问追答
追答
select
province,
COUNT(case when birthday>'20150507' and birthday'时间段' and birthday<='时间段' then 1 else null end)
from 表
group by province
抱歉 写漏了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询