怎样查找统计相同名称的金额值,请帮我,谢谢。

例如:

三个字段:名称 金额 备注
wwww 100 大dfda
wwee 200 sdfa
dddd 289 asdf
wwww 100 fdgbb
ereww 7899 sdaf
wwee 200 aerwre
rttty 100 rewyy
注意:当名称相同时,金额也相同。请统计表中金额总和,当名称和金额都相同的记录重复时,只统计一次金额。答案是100+200+289+7899+100

---------------------------------------------------------------

select 名称 ,sum(金额)
from (select distinct 名称 ,金额 from yourTable) as TableA
group by 名称

---------------------------------------------------------------

select sum(金额) from
(select distinct 名称,金额 from table1) as t1
---------------------------------------------------------------

同意
---------------------------------------------------------------

to: twht(Hmily) 不加as 好像不行吧!!!!

select sum(金额) from
(select distinct 名称,金额 from table1) as t1

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus