sqlserver 分类汇总
1个回答
展开全部
select t1.shop,sum(t1.qty) as qty,t2.sum_qty from 表名 as t1,
(select sum(qty) as sum_qty from 表名) as t2
group by t1.shop,t2.sum_qty
时间条件你自己加一下吧,应该没问题吧?
追问
我这个时间条件应该怎么选? 比如我t1 是12-1到12-30号 t2的汇总也是要12-1到12-30号的 只能t1,t2都加where 时间限制?
追答
是啊,只能这样,要不数据就不准确了
select t1.shop,sum(t1.qty) as qty,t2.sum_qty from 表名 as t1,
(select sum(qty) as sum_qty from 表名 where 时间限制) as t2
where t1.时间限制.....
group by t1.shop,t2.sum_qty
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询