【发布时间】:2020-04-13 00:43:45
【问题描述】:
我有一个餐桌视频
videoId | channelId | commentCount
a | 1 | 5
b | 1 | 3
c | 2 | 1
还有一个表频道。 video.channelId 映射到 channel.Id
Id
1
2
3
对于每个 videoId,我需要该频道的评论计数和所有评论计数的总和。
所以最终结果应该是:
videoId | channelId | commentCount | commentCount_sum
a | 1 | 5 | 8
b | 1 | 3 | 8
c | 2 | 1 | 1
到目前为止我的代码:
SELECT v.videoId, v.channelId, v.commentCount, SUM(v.commentCount) commentCount_sum
FROM videos v
JOIN channels c
ON c.Id = v.channelId
GROUP BY v.videoId
但我没有得到每个 videoId 的正确 commentCount_sum - commentCount_sum 与 commentCount 相同?
【问题讨论】: