GROUP_CONCAT 个 SUM
GROUP_CONCAT of SUMs
我有两个 select 查询都给出了正确的结果:
SELECT SUM(value) AS "sum1" FROM table GROUP BY id1
和
SELECT SUM(value) AS "sum2" FROM table GROUP BY id1, id2
sum1
是所有 sum2
项目的总和,我想要一个查询,它给我的结果是 sum1
和所有 [=15] 的 GROUP_CONCAT =]-项目。但是如何在 GROUP_CONCAT 中为 sum2
-items 元素定义 GROUP BY?
SELECT SUM(value) AS "sum1", GROUP_CONACAT(SUM(value) AS "sum2" ... (?))
FROM table GROUP BY id1
你应该使用子查询来解决它,使用下面的查询,我相信它会解决你的问题
select sum(t.part_sum) as sum1, group_concat(t.part_sum) as sum2 from (select sum(value) as part_sum from table group by id1, id2) as t
我有两个 select 查询都给出了正确的结果:
SELECT SUM(value) AS "sum1" FROM table GROUP BY id1
和
SELECT SUM(value) AS "sum2" FROM table GROUP BY id1, id2
sum1
是所有 sum2
项目的总和,我想要一个查询,它给我的结果是 sum1
和所有 [=15] 的 GROUP_CONCAT =]-项目。但是如何在 GROUP_CONCAT 中为 sum2
-items 元素定义 GROUP BY?
SELECT SUM(value) AS "sum1", GROUP_CONACAT(SUM(value) AS "sum2" ... (?))
FROM table GROUP BY id1
你应该使用子查询来解决它,使用下面的查询,我相信它会解决你的问题
select sum(t.part_sum) as sum1, group_concat(t.part_sum) as sum2 from (select sum(value) as part_sum from table group by id1, id2) as t