高分求一SQL代码段(100分)

  • 主题发起人 龙之天涯
  • 开始时间

龙之天涯

Unregistered / Unconfirmed
GUEST, unregistred user!
现有如下格式要求<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;合计 &nbsp;a &nbsp; b &nbsp; c &nbsp; d &nbsp; e ....<br>&nbsp; &nbsp;分组1 16 &nbsp; &nbsp;5 &nbsp; 3 &nbsp; 2 &nbsp; 3 &nbsp; 1<br>&nbsp; &nbsp;分组2 10 &nbsp; &nbsp;1 &nbsp; 2 &nbsp; 3 &nbsp; 3 &nbsp; 1<br>如何使用最简单的SQL代码求出如上结果集??
 
的abcde是字段吗?
 
select (a+b+c+d+e+...) as total,a,b,c,d,e,... from table<br><br>还有其他要求吗?不会这么简单的吧
 
不是这样的<br>我是想实现在一表中同时计算出汇总的项,以及明细项目栏出来
 
这是行转列问题,网上有好多行转列,可以参考下面的<br>http://blog.chinaunix.net/u/29134/showart_364659.html
 
select 分组,sum() '合计',isnull(select sum() from table1 where 条件=A.条件 and ***查询出a的条件 group by ***,0) a,isnull(select sum() from table1 where 条件=A.条件 and ***查询出b的条件 group by ***,0) b,isnull(select sum() from table1 where 条件=A.条件 and ***查询出c的条件 group by ***,0) c,isnull(select sum() from table1 where 条件=A.条件 and ***查询出d的条件 group by ***,0) d,isnull(select sum() from table1 where 条件=A.条件 and ***查询出e的条件 group by ***,0) e<br>from table1 A<br>group by 分组
 
具体的你可以把表名、字段名写出来,我帮你写[:D]
 
典型的动态交叉表
 

Similar threads

回复
0
查看
865
不得闲
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
933
SUNSTONE的Delphi笔记
S
顶部