以下 SQL 语句产生下面列出的结果。问题是,如何修改此语句以提供每个 post_id 的总和?例如,post_id 1 应该 = 25,而 post_id 2 应该 = 758。
SELECT t.post_id,
SUM(maxpostmetric) as sumvalue
FROM (
SELECT post_metrics.post_id,
post_metrics.post_metric_type_id,
MAX( post_metrics.value ) maxpostmetric
FROM post_metrics
INNER JOIN posts ON posts.id = post_metrics.post_id
WHERE posts.channel_id = 2268
GROUP BY post_metrics.post_id, post_metrics.post_metric_type_id
ORDER BY post_metrics.id
)t
INNER JOIN post_metric_types ON post_metric_types.id = t.post_metric_type_id
GROUP BY t.post_id, t.post_metric_type_id
post_id:值;1:0; 1:25;1:0; 2:110;2:588; 2:60;
1 = 25; 2 = 758。
谢谢