Total_payments是每个playerid的所有付款之和。如何获得一行每个ID只显示playerid和total_payments。我不想要重复的。
SELECT playerid
, payment_amount, SUM(payment_amount) OVER (PARTITION BY playerid) AS total_payment
FROM DEPOSIT$
| playerid | payment_amount| total_payment |
|:1002 |:10 :| 60 :|
|:1002 |:50 :| 60 :|
|:1003 |:40 :| 50 :|
|:1003 |:10 :| 50 :|
|:1004 |:10 :| 30 :|
|:1004 |:20 :| 30 :|
|:1006 |:100 :| 100 :|
|:1008 |:60 :| 60 :|
谢谢!
通常这是正确的方法-使用sum()和group by子句。因为你是根据玩家id分组的,所以每个玩家id都是唯一的,并且支付金额的总和将被相加。这实际上只是一个标准的sql查询,用于按某些属性求和。
SELECT
playerid,
SUM(payment_amount) AS total_payment
FROM
DEPOSIT$
GROUP BY
playerid
也许你忘记了最后的group by子句?