我有两个select-queries,它们都能给出正确的结果:
SELECT SUM(value) AS "sum1" FROM table GROUP BY id1
和
SELECT SUM(value) AS "sum2" FROM table GROUP BY id1, id2
sum1
是所有sum2
项的总和,我想要一个查询,它会给我sum1
的结果和所有sum2
项的GROUP_CONCAT项。但是如何在GROUP_CONCAT中为sum2
- items元素定义GROUP BY?
SELECT SUM(value) AS "sum1", GROUP_CONACAT(SUM(value) AS "sum2" ... (?))
FROM table GROUP BY id1
答案 0 :(得分:0)
您应该使用子查询解决它,使用以下查询,我相信它将解决您的问题
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