当前位置:数据库 > SQLServer >>

无规律自定义分段的分类汇总+交叉表处理

答案:


/*--原帖地址:http://community.csdn.net/Expert/topic/3845/3845290.xml?temp=.3689386--*/

--测试数据create table tb(编号 int,性质 varchar(10),数量 int,指标1 decimal(10,1),指标2 decimal)insert tb select 1 ,'00' ,10,1.1 ,10union all select 2 ,'01' ,20,1.2 ,20union all select 3 ,'00' ,30,1.5 ,10union all select 4 ,'01' ,40,1.9 ,35union all select 5 ,'00' ,40,1.2 ,20

/*--处理要求

要求得到下述结果:

a                      范围               性质(00)         性质(01)         ----------------- ---------------- -------------- -------------- 指标1               <1.0              .00            .00                         1.0-1.29        .63            .63                         1.3-1.59        .38            .38                         1.9-1.99        .00            .00                          >=2               .00            .00指标1平均值                        1.27           1.55指标2               <10              .00             .00                         10-31            1.00           1.00                         31-50            .00            .00                         >=50             .00            .00指标2平均值                        13.33          27.50数量合计:                          80.00          60.00------------------------------------------------------------------

分类说明:

                    范围            性质(00)                               性质(01)指标1         <1.0            0                                                    0                               1.0-1.29      (10+40)/(10+30+40)                 20/(20+40)                   1.3-1.59      30/(10+30+40)                            0                   1.6-1.99      0                                                    40/(20+40)                   >=2              0                                                    0指标1平均值:              (1.1+1.5+1.2)/3                          (1.2+1.9)/2

指标2        <10              0                                                     0                  10-30            (10+30+40)/(10+30+40)          20/(20+40)                   31-50            0                                                 &

上一个:逐记录导出text/ntext字段值为文本文件
下一个:不通过删除重建方式 重置序列值得简单方式。

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,