SELECT
player_id,
SUM(CASE WHEN transaction_type = 'deposit' THEN amount_local ELSE 0 END) AS total_deposits,
SUM(CASE WHEN transaction_type = 'withdrawal' THEN amount_local ELSE 0 END) AS total_withdrawals
FROM your_table_name
GROUP BY player_id;
-- For the first table
SELECT
player_id,
transaction_type,
SUM(amount_local) AS total_amount
FROM
table1
GROUP BY
player_id,
transaction_type;
-- For the second table
SELECT
player_id,
transaction_type,
SUM(amount_local) AS total_amount
FROM
table2
GROUP BY
player_id,
transaction_type;
2条答案
按热度按时间li9yvcax1#
其实很简单您可以使用SQL的SUM()函数和CASE语句来区分存款和取款交易,以便检索按player_id聚合的总存款和取款金额。下面是一个示例查询:
Your_table_name
应该更改为表的名称。每个玩家的总存款和取款金额是通过分别为每个player_id
添加amount_local
列中的值来确定的。希望这对你有帮助,让我知道如果你需要更多的帮助。
2vuwiymt2#
transaction_type列可用于区分存款和取款,而GROUP BY子句可用于按player_id对结果进行分组。下面是两个表的说明SQL命令:
您将从上面的查询中收到一个返回集,其中包括player_id、transaction_type和total_amount列。Transaction_type将是“存款”或“取款”,total_amount将是每个player_id和transaction_type组合的金额总和。
希望它能起作用:)