关于分类统计的问题
向各位高手求解:
已知表包含字段学号、姓名、生源地区代码(6位)、生源地址,地区代码根据生源地址的不同而不同,比如:学生是北京的,地区代码就为“11****”,天津的就是“12****”。现在要根据地区代码的不同统计出各个省份的学生总人数。
[解决办法]
create cursor xxb (姓名 c(8),地区代码 c(6))
insert into xxb values ("aaa","110000")
insert into xxb values ("bbb","120000")
insert into xxb values ("ccc","110101")
insert into xxb values ("ddd","120000")
insert into xxb values ("eee","130129")
insert into xxb values ("fff","120101")
insert into xxb values ("ggg","140105")
select *,sum(iif(left(地区代码,2)=="11",1,0)) as 北京市,;
sum(iif(left(地区代码,2)=="12",1,0)) as 天津市,;
sum(iif(left(地区代码,2)=="13",1,0)) as 河北省,;
sum(iif(left(地区代码,2)=="14",1,0)) as 山西省 from xxb into cursor xxb1 group by 地区代码
browse
[解决办法]
[code=VB][/code]
create cursor xxb (姓名 c(8),地区代码 c(6))
insert into xxb values ("aaa","110000")
insert into xxb values ("bbb","120000")
insert into xxb values ("ccc","110101")
insert into xxb values ("ddd","120000")
insert into xxb values ("eee","130129")
insert into xxb values ("fff","120101")
insert into xxb values ("ggg","140105")
select *,left(地区代码,2) as 代码,sum(iif(left(地区代码,2)=="11",1,0)) as 北京市,;
sum(iif(left(地区代码,2)=="12",1,0)) as 天津市,;
sum(iif(left(地区代码,2)=="13",1,0)) as 河北省,;
sum(iif(left(地区代码,2)=="14",1,0)) as 山西省 from xxb into cursor xxb1 group by 代码
browse
[解决办法]
select left(生源地区代码,2) as dm,count(学号) as rs from 表名 group by dm
[解决办法]
[code=VB][/code]
create cursor xxb (姓名 c(8),地区代码 c(6))
insert into xxb values ("aaa","110000")
insert into xxb values ("bbb","120000")
insert into xxb values ("ccc","110101")
insert into xxb values ("ddd","120000")
insert into xxb values ("eee","130129")
insert into xxb values ("fff","120101")
insert into xxb values ("ggg","140105")
sys(3099,70) &&VFP6.0去掉该行代码
select *,left(地区代码,2) as 代码,sum(iif(left(地区代码,2)=="11",1,0)) as 北京市,;
sum(iif(left(地区代码,2)=="12",1,0)) as 天津市,;
sum(iif(left(地区代码,2)=="13",1,0)) as 河北省,;
sum(iif(left(地区代码,2)=="14",1,0)) as 山西省 from xxb into cursor xxb1 group by 代码 order by 代码
browse
[解决办法]
select *,left(地区代码,2) as 代码,count(left(地区代码,2)) as 人数 from xxb into cursor xxb1 group by 代码 order by 代码
browse
[解决办法]
Select Left(生源地区代码,2) As DQDM,Count(*) As rs From 表名 Group By DQDM