如何在SQL中获取总计作为单独的总计列

时间:2019-08-22 19:16:37

标签: sql sum

我正在尝试获取Total_Paid列

Product     Timestamp   Paid                  Total_Paid
A             201801    12                     36
A             201802    11                     36
A             201803    13                     36
B             201801    10                     45
B             201802    15                     45
B             201803    20                     45

1 个答案:

答案 0 :(得分:1)

您可以使用窗口功能。例如:

select
  *,
  sum(paid) over(partition by product) as total_paid
from t