你的分组不正确。试试这样,看是不是你想要的:
select ID,Name,sum(Price) as TotalPrices from talbe group by ID,Name你写的语句,如果有重复的记录,sum(price)就不等于price了。
解决方案 »
- 两表对账,求思路,求sql!!在线等。。。
- 求一sql 语句,查询并修改后插入(在线急等)
- 在线等,请教sql 2000中的跨数据库所有权链接的问题
- 急!!各位帮忙一下,我要导一个数据库中的表到另一数据库中的表里面。
- 怎么根据不同的参数用不同的表
- 还原数据库时出错
- SQLServer2000在建立索引视图后如何修改基表?
- ●一个很菜的问题:如何格式化输出一个字段值,即如何将float类型的字段以0.00样式输出???select 0.00 xxx from table,结果全是.00???
- 谁有sql server2000 standard版的cd_key,
- jsp页面向数据库增加数据和修改数据都会应为乱码而失败
- 帮忙写个Sql,100分哦
- 输入输出,请问错在哪里
错了,应该是这样:你的分组不正确。试试这样,看是不是你想要的:
select [Name],sum(Price) as TotalPrices from talbe group by [Name]
我想要的结果是:
------------------------------------------
ID, Name, Price, TotalPrices
1, Aaa , 2.0 6
2, Bbb , 3.0 6
3, Ccc , 1.0 6
------------------------------------------
继续等...
select a.*,totalprice
from tablename a , (select sum(price) as totalprices from tablename) b
------------------------------------------
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们,帮帮忙吧...
Select @s=sum(Price) from t1 where Type = 'A'
select *,@s as Total from t1 where Type = 'A'