可以用case when
group by
with cube
之類的來實現
group by
with cube
之類的來實現
解决方案 »
- 求sql函数 判断一个字符串里的字符有没有在另一个字符串里出现过
- sql中的判断语句
- 让一个字段的时间减去4天,提示错误
- 数据插入的其本问题,急求大吓帮忙啊!!!
- 求如何动态隐藏列为空的SQL语句
- 关于数据库备份方式的问题
- 没有日志文件怎么恢复数据库 多谢并给分50
- 不好意思,新人请教一个问题update可以更新select查询出来的表吗?
- 初次到数据库来提问,希望能得到各位的帮助:怎么将word文档弄进SQL数据库啊?二进制的。具体的操作步骤。
- 请教,为何编辑一次存贮过程,在代码的最前与最后处每次增一空行,alter 与 proc之间每次加一个空格呢?
- 50分跪求
- 这条语句该怎么写(在线等......)
select a.*,b.* from
(select no,min(invno) as ino,typ1=sum(case when type='1' then score else 0 end),
typ2=sum(case when type='2' then score else 0 end),'表A' as where_from
from qqa1 group by no union
select case when grouping(no)=1 then 'hj' else no end ,rtrim(no)+'小计' as ino,sum(typ1) as typ1 ,sum(typ2) as typ2,' ' as where_from
from (select no,min(invno) as ino,typ1=sum(case when type='1' then score else 0 end),typ2=sum(case when type='2' then score else 0 end)
from qqa1 group by no) dd group by no with rollup ) a left join qqc1 b on b.no=a.no and a.where_from<>' ' order by a.no,a.ino
select case when substring(ida,2,2)='合计' then ' ' else where_from end as where_from,
* from
(select isnull(id,'总计') as ida,* from
(select a.*,b.* from
(select case when grouping(invno)='1' then rtrim(no)+'合计'
else no end as id,
min(invno) as ino,typ1=sum(case when type='1' then score else 0 end),
typ2=sum(case when type='2' then score else 0 end),'表A' as where_from
from qqa1 group by no,invno with rollup) a left join qqc1 b on b.no=a.id
)c)d