2013-08-23 85 views
0

我有以下栏目:-SQL-求和其他列的值

merchant_id 
euro 

我想通过merchant_id总结所有欧元区记录,只返回total sum per merchant_id

所以,如果有3条记录,如:

euro | merchant_id 
4  | 1 
5.4 | 2 
2.5 | 1 

结果应该是:

euro | merchant_id 
6.5 | 1 
5.4 | 2 

如何在地球上我该怎么办呢?

谢谢。

回答

0

您需要通过使用组,总结起来。

SELECT SUM(euro) AS euro,merchant_id 
FROM table_name 
GROUP BY merchant_id 
0
select 
    merchant_id 
    ,sum(euro) 
from 
    <your_table_name> 
group by 
    merchant_id 
0

集团由可能是解决:

select merchant_id, SUM(euro) as total 
    from <your_table> 
    group by merchant_id 
    order by merchant_id; 

享受;-)