-1

嗨,我有以下选择语句

      select
      a.amount
      ,b.des
      ,a.id
      ,SUM(a.amount) as total
      ,b.id  
      from t_sales a
      left outer join t_location b on(b.id=a.orgId)
      where a.Id=@salesId   and
      a.sId=@supId
      GROUP BY a.amount, b.des, a.Id,b.id;

一切都很好,除了总数。我正在尝试获取 a.amount 的总数,它返回 15 个值,所以我想拥有所有 15 个值的总数。请让我知道如何解决它。谢谢

4

3 回答 3

0

您应该a.amount从选择列表中删除列(选择列表中不应存在聚合列)

 select b.des, a.id, a.amount  ,SUM(a.amount) over(partition by 1) as total, b.id from t_sales a left outer join t_location b on(b.id=a.orgId)
    where a.Id=@salesId and a.sId=@supId GROUP BY b.des, a.Id, b.id;
于 2013-10-24T05:13:08.990 回答
0

Please try:

select
    a.amount
    ,b.des
    ,a.id
    ,SUM(a.amount) over(partition by 1) as total
    ,b.id  
from t_sales a
    left outer join t_location b on(b.id=a.orgId)
where 
    a.Id=@salesId   and
    a.sId=@supId;
于 2013-10-24T05:09:56.077 回答
0

你能试一下吗

select            a.amount, b.des, a.id, b.id,
                  (select            sum(a.amount)
                  from              t_sales a
                  left outer join   t_location b on (b.id = a.orgId)
                  where             a.Id = @salesId   
                  and               a.sId = @supId
                  GROUP BY          b.des, a.Id, b.id) as total
from              t_sales a
left outer join   t_location b on (b.id = a.orgId)
where             a.Id = @salesId   
and               a.sId = @supId
GROUP BY          a.amount, b.des, a.Id, b.id;
于 2013-10-24T05:07:01.460 回答