你的分组不正确。试试这样,看是不是你想要的:
select ID,Name,sum(Price) as TotalPrices from talbe group by ID,Name你写的语句,如果有重复的记录,sum(price)就不等于price了。

解决方案 »

  1.   


    错了,应该是这样:你的分组不正确。试试这样,看是不是你想要的:
    select [Name],sum(Price) as TotalPrices from talbe group by [Name]
      

  2.   

    谢谢楼上的,可这不是我想要的。
    我想要的结果是:
    ------------------------------------------
    ID,  Name,    Price,   TotalPrices
    1,    Aaa   , 2.0         6
    2,    Bbb   , 3.0         6
    3,    Ccc   , 1.0         6
    ------------------------------------------
    继续等...
      

  3.   


    select a.*,totalprice
    from tablename a , (select sum(price) as totalprices from tablename) b
      

  4.   

    再说明一下吧,实际上这张表还有其它列,
    ------------------------------------------
    ID,  Name,    Price,    Type
    1,    Aaa   , 2.0       A
    2,    Bbb   , 3.0       A  
    3,    Ccc   , 1.0       B
    4,     Ddd   ,  2.5       C  
    ------------------------------------------
    而我要加上条件 Type = A 的。想要显示的是:
    ------------------------------------------
    ID,  Name,    Price,    Type,  Total
    1,    Aaa   , 2.0       A,      5.0
    2,    Bbb   , 3.0       A,      5.0     
    ------------------------------------------XDJM们,帮帮忙吧...
      

  5.   

    DECLARE @s int
    Select @s=sum(Price) from t1 where Type = 'A'
    select *,@s as Total from t1 where Type = 'A'
      

  6.   

    已经可以了,感谢中海兄弟,也谢谢cctv555捧场...