0

我有以下列:

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

我到底该怎么做?

谢谢。

4

3 回答 3

0
select
    merchant_id
    ,sum(euro)
from
    <your_table_name>
group by
    merchant_id
于 2013-08-23T08:22:53.653 回答
0

Group by 可能是解决方案:

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

请享用 ;-)

于 2013-08-23T08:24:55.450 回答
0

您需要使用 group by 并总结它们。

SELECT SUM(euro) AS euro,merchant_id
FROM  table_name
GROUP BY merchant_id
于 2013-08-23T08:25:49.263 回答