选择合并的 SQL 过程
我的程序是:
create procedure "news"
as
select newsdate,COUNT(B.id) as total from news B
where B.newsyear < GETDATE()
Group by B.newsdate
select newsdate,COUNT(B.id) as total from news B
where B.status='WAITING' and B.cancel='1'
Group by B.newsdate
结果:
newsdate total
2011 4
2010 8
newsdate total
2011 2
2010 3
如何合并年份总计以获得此结果集:
newsdate total
2011 6 {4 + 2}
2010 11 {8 + 3}
My procedure is:
create procedure "news"
as
select newsdate,COUNT(B.id) as total from news B
where B.newsyear < GETDATE()
Group by B.newsdate
select newsdate,COUNT(B.id) as total from news B
where B.status='WAITING' and B.cancel='1'
Group by B.newsdate
Results:
newsdate total
2011 4
2010 8
newsdate total
2011 2
2010 3
How can I merge year totals to obtain this result set:
newsdate total
2011 6 {4 + 2}
2010 11 {8 + 3}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
使用简单的 or 语句(如果确实是同一个表):
或使用 union all + sum 聚合(如果是不同的表):
using a simple or statement (if it's indeed the same table):
or using union all + a sum aggregate (if it's different tables):