关于with RollUp的特殊使用情况。求救各位大侠指点迷山

hellogenius 2006-09-12 05:07:13
select s.a as 单位名称,sum(s.b) as 本期产量,(select sum(s1.b) from s as s1 where s1.year=2006 and s1.month=9 and s1.a=s.a ) as 本月产量
from s where s.year=2006 and s.month between 1 and 9 group by s.a with rollup order by s.a desc。
这个汇总程序汇总的是所有单位 本期产量之和,却不能实现对 所有单位本月产量进行汇总,请问有什么方法可以对本月产量一起进行汇总吗???谢谢了。
...全文
90 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellogenius 2006-09-12
  • 打赏
  • 举报
回复
这位大侠说得很有创意,但是提示错误啊,s.year,s.month 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中
xiequanqin 2006-09-12
  • 打赏
  • 举报
回复
select s.a as 单位名称,sum(s.b) as 本期产量,(case when s.year=2006 and s.month=9 then sum(s.b) else 0 end) as 本月产量
from s where s.year=2006 and s.month between 1 and 9 group by s.a with rollup order by s.a desc。
hellogenius 2006-09-12
  • 打赏
  • 举报
回复
求救~~~

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧