select a.major,isnull(year70,0),isnull(year75,0),isnull(year80,0) from
(select distinct major from table1) a,
(select major,count(*) year70 from table_1
where to_char(brth,'yyyy') between '70' and '75' group by major) b,
(select major,count(*) year75 from table_1
where to_char(brth,'yyyy') between '76' and '80' group by major) c,
(select major,count(*) year80 from table_1
where to_char(brth,'yyyy') between '82' and '85' group by major) d,
where b.major = a.major(+)
and c.major = a.major(+)
and d.major = a.major(+)
select distinct
"专业名称",
(select sum(出生日期) from table1 b where b.专业名称 =a.专业名称 [and 出生日期条件1]) as "70-75年人数",
(select sum(出生日期) from table1 b where b.专业名称 =a.专业名称 [and 出生日期条件2]) as "75-80年人数",
(select sum(出生日期) from table1 b where b.专业名称 =a.专业名称 [and 出生日期条件3]) as "80-85年人数"
from table1 a ;
table1
姓名,c,专业,email,爱好
现在要统计出各个专业里70-75年,75-80年,80-85年所有学生的人数
比如:
专业名称,70-75年人数,75-80年人数,80-85年人数
专业1 ,23, 34, 12
这个sql语句怎么写??
select distinct
"专业名称",
(select sum(出生日期) from table1 b where b.专业名称 =a.专业名称 [and 出生日期条件1]) as "70-75年人数",
(select sum(出生日期) from table1 b where b.专业名称 =a.专业名称 [and 出生日期条件2]) as "75-80年人数",
(select sum(出生日期) from table1 b where b.专业名称 =a.专业名称 [and 出生日期条件3]) as "80-85年人数"
from table1 a ;