我尝试从我的表中选择并汇总以获得Total,但是我失败了。这里是我的表和值 mysql select * from table group id by rollup
,结果我想这样
这可能吗? 我的查询:
select * from mytable group by id with rollup;
但我查询未能获得累积值,请告诉我怎么感谢
我尝试从我的表中选择并汇总以获得Total,但是我失败了。这里是我的表和值 mysql select * from table group id by rollup
,结果我想这样
这可能吗? 我的查询:
select * from mytable group by id with rollup;
但我查询未能获得累积值,请告诉我怎么感谢
试试这个:
select id,sum(qty),sum(import),sum(loss),sum(results)
from mytable group by id asc with rollup;
Thanks @reds is really helpful –
你可以做类似下面
select coalesce(CAST(id as CHAR(50)),'Total'),
max(local),sum(import),sum(loss),sum(results) from mytable group by id asc with rollup
您必须在列 –
上使用聚合函数总和请参见https://meta.stackoverflow.com/quest离子/ 333952/why-should-i-provide-an-mcve-for-what-seem-to-the-very-simple-sql-query – Strawberry