请教高手~~~mysql怎么样实现同id不同行加总(sum)后输出,如图:
就是说想得到不同hproject_id的hmov,hteu,htun,income,profit的sum值,但是原因是hproject_id的值很大,假如用where语句一条一条写的话会很麻烦,求高手怎么通过循环语句或别的方法来实现呢?
就是说想得到不同hproject_id的hmov,hteu,htun,income,profit的sum值,但是原因是hproject_id的值很大,假如用where语句一条一条写的话会很麻烦,求高手怎么通过循环语句或别的方法来实现呢?
解决方案:40分
是这样吗:
select hproject_id,
sum(hmov) hmov,
sum(hteu) hteu,
sum(htun) htun,
sum(income) income,
sum(profit) profit
from tb
group by hproject_id
select hproject_id,
sum(hmov) hmov,
sum(hteu) hteu,
sum(htun) htun,
sum(income) income,
sum(profit) profit
from tb
group by hproject_id