MySQL查询特定客户及其交易详细信息

时间:2019-06-02 13:45:26

标签: php mysql sql

我如何查询特定客户的所有交易金额,货币并获得该客户以各种货币进行的交易总额。 enter image description here

2 个答案:

答案 0 :(得分:0)

尝试一下。这将返回每个客户每种货币的金额总和。

SELECT customer_id,currency_code,SUM(amount) 
FROM your_table
--if you wants to see the result for a specific customer, add this following filter
WHERE customer_id = <put customer id here>
GROUP BY customer_id,currency_code

答案 1 :(得分:0)

这里是查询以获取特定客户在货币方面的总交易记录。

对于所有客户:

SELECT customer_id,currency_code,SUM(amount) 
FROM transactions GROUP by customer_id, currency_code

对于特定客户:

SELECT customer_id,currency_code,SUM(amount) 
FROM transactions 
WHERE customer_id = <put it your customer_id> 
GROUP by customer_id, currency_code