我需要一些帮助,我的MySQL查询。我有一个表,看起来像:mysql sum(column2 - column1)with rollup
然后,我想这个查询选择:
select id, class, defaut, input, round(input - defaut) test from table1
group by class, id with rollup
我想要的输出,如:
但我的查询给我这样:
请您的帮助,谢谢
我需要一些帮助,我的MySQL查询。我有一个表,看起来像:mysql sum(column2 - column1)with rollup
然后,我想这个查询选择:
select id, class, defaut, input, round(input - defaut) test from table1
group by class, id with rollup
我想要的输出,如:
但我的查询给我这样:
请您的帮助,谢谢
你需要总结的默认输入和计算的领域,以获得预期的输出,否则rollup
会简单地从过去的记录返回值:
select id, class, sum(defaut), sum(input), sum(round(input - defaut)) test from table1
group by class, id with rollup
非常感谢。你的回答非常有帮助 –
我想你可以用更少的行和/或sqlfiddle/rextest来说明问题。 – Strawberry
您可以选择id,class,defaut和input,但只能按其中的两列进行分组。虽然存在功能上的依赖性,但出于ROLLUP的目的,这并不合理。 – Strawberry