全部家当求答,关于分类统计及大类中的小类统计,用SQL(45分)

  • 主题发起人 主题发起人 zhch1100
  • 开始时间 开始时间
Z

zhch1100

Unregistered / Unconfirmed
GUEST, unregistred user!

运行环境:D6=+ACCESS=ADOqueryy
gzxx有 dwbh,xm,gwdm,zg,xj,sdgz..等字段
dwbh xm gwdm zg xj sdgz...
01 张1 1511 30 0 1500...
01 张2 1511 30 0 1480...
01 李1 2611 25 5 1300...
01 李2 2611 25 5 1330...
01 肖1 3111 30 0 1210...
01 王1 4241 28 2 1100...
01 王2 5211 30 0 1400...
02 张3 1511 30 0 1500...
02 张4 1511 30 0 1480...
02 李3 2611 25 5 1300...
02 李4 2611 25 5 1330...
02 肖2 3111 30 0 1210...
02 王3 4241 28 2 1100...
02 王4 5211 30 0 1400...
03 张5 1511 30 0 1500...
03 张6 1511 30 0 1480...
03 李5 2611 25 5 1300...
03 李6 2611 25 5 1330...
03 肖3 3111 30 0 1210...
03 王5 4241 28 2 1100...
03 王6 5211 30 0 1400...
. . . . ...
. . . . ...
需要实现的统计功能就是
dwbh zrs sdgz
01 7 9320
01 2 2980 //dwbh like '1%'
01 2 2630 //dwbh like '2%'
01 3 3710 //dwbh like '3%' or dwbh like '4%' or dwbh like '5%'
02 7 9320
02 2 2980 //dwbh like '1%'
02 2 2630 //dwbh like '2%'
02 3 3710 //dwbh like '3%' or dwbh like '4%' or dwbh like '5%'
03 7 9320
03 2 2980 //dwbh like '1%'
03 2 2630 //dwbh like '2%'
03 3 3710 //dwbh like '3%' or dwbh like '4%' or dwbh like '5%'
在以dwbh为大类的查询基础上,再对gwdm进行小分类,请求大虾多多指导
 
对gzxx表中的dwbh进行统计,同时还要对gwdm进行统计,比如统计出dwbh为01的共有7个人,
sdgz字段之和为9320,在字段dwbh为01中,其中字段gwdm以1打头的有2个人,sdgz字段之和为2980,gwdm以2打头的有2个人,
sdgz字段之和为2630,字段gwdm以3或4或打头的3个人,sdgz字段之和为3710,同样统计出02的总人数,以及分人数及分sdgz数
 
按你这个格式很难实现;要是这样
gwdm zrs sdgz 1rs sdgz 2rs sdgz 3rs sdgz
01 7 9320 2 2980 2 2630 3 3710
.....这样到是有可能
 
如果按你的这种方式,该怎么写SQL语句了,我使用的是adoquery+access2000
 
to 王颜康 你的select a.gwbh是什么意思,我是想把gzxx表进行统计,得到的就是你的这个结果也很好.谢谢你这么晚了还在为我解答
gwdm zrs sdgz 1rs sdgz 2rs sdgz 3rs sdgz
01 7 9320 2 2980 2 2630 3 3710
 
哦~打错了。是a.dwbh
 
我试试不知道对不队
select a.dwbh,
select count(*) from b.gzxx where a.gwbh=b.gwbh as zrs,
select sum(sdgz) from gzxx where a.gwbh=gwbh as 总sdzg,
select count(*) from gzxx where a.gwbh=gwbh and dwdm like '1%' as 1rs,
select sun(sdgz) from gzxx where a.gwbh=gwbh and dwdm like '1%' as 1sdgz,
select count(*) from gzxx where a.gwbh=gwbh and dwdm like '2%' as 2rs,
select sun(sdgz) from gzxx where a.gwbh=gwbh and dwdm like '2%' as 2sdgz,
select count(*) from gzxx where a.gwbh=gwbh and dwdm like '3%' as 3rs,
select sun(sdgz) from gzxx where a.gwbh=gwbh and dwdm like '3%' as 3sdgz,
select count(*) from gzxx where a.gwbh=gwbh and dwdm like '4%' as 4rs,
select sun(sdgz) from gzxx where a.gwbh=gwbh and dwdm like '4%' as 4sdgz
from gzxx a
group by a.dwbh
 
接受答案了.
 
后退
顶部