接任务,赚取用不完的金币中国教程网
《Photoshop专家讲堂》光盘热售
参与论坛活动,快速赚取金币精品素材,中英文字体
发新话题
打印

分段统计问题一则

分段统计问题一则


有一张表  

id    a    b    c  
001    9    8    7  
002  10    7    6  
003    8    9    5  
004    7    6    9  
005    6  10  10      
006    5    9    8  
……  

如何用foxpro、access对字段a,b,c  进行分段统计,即5~6,7~8,9~10三段  
---------------------------------------------------------------  

create  table  #temp1(id  char(3),a  int,b  int,c  int)  
insert  into  #temp1(id,a,b,c)values('001',9,8,7)  
insert  into  #temp1(id,a,b,c)values('002',10,7,6)  
insert  into  #temp1(id,a,b,c)values('003',8,9,5)  
insert  into  #temp1(id,a,b,c)values('004',7,6,9)  
insert  into  #temp1(id,a,b,c)values('005',6,10,10)      
insert  into  #temp1(id,a,b,c)values('006',5,9,8)  

select  '5-6'id,  
     sum(case  when  a  between  5  and  6  then  1  else  0  end)  a,  
     sum(case  when  b  between  5  and  6  then  1  else  0  end)  b,  
     sum(case  when  c  between  5  and  6  then  1  else  0  end)  c   
from  #temp1  
union  
select  '7-8'id,  
     sum(case  when  a  between  7  and  8  then  1  else  0  end)  a,  
     sum(case  when  b  between  7  and  8  then  1  else  0  end)  b,  
     sum(case  when  c  between  7  and  8  then  1  else  0  end)  c   
from  #temp1  
union  
select  '9-10'id,  
     sum(case  when  a  between  9  and  10  then  1  else  0  end)  a,  
     sum(case  when  b  between  9  and  10  then  1  else  0  end)  b,  
     sum(case  when  c  between  9  and  10  then  1  else  0  end)  c   
from  #temp1  

drop  table  #temp1  

结果:  
----------------------------  
id              a                b                c      
5-6            2            1            2  
7-8            2            2            2  
9-10            2            3            2  
------------------------------  

是要这个东西吗?  
---------------------------------------------------------------
发新话题 返回列表