sql语句求和

表1
名称 单位 金额
a b 100
a b 200
c b 100
通过什么语句可以将表中修改为
名称 单位 金额
a b 300
c b 100

第1个回答  2018-09-20
select sum(d1) as d1sum, sum(d2) as d2sum, sum(d3) as d3sum from your_table_name where name in ('张三', '李四') and time = '20180919';

第2个回答  2014-10-30
select (A.sum_pi - B.sum_ci) as result
from
(select sum(t.数量) as sum_pi,
t.编码
from t
where t.编码 = '4001'
and t.类型 = 'pi'
group by t.编码) A,
(select sum(t.数量) as sum_ci,
t.编码
from t
where t.编码 = '4001'
and t.类型 = 'ci'
group by t.编码) B
where A.编码 = B.编码
第3个回答  2012-12-30
你可以先将汇总的结果存入一个临时表,然後删除原表资料,最後再将临时表的资料写入原表
步骤如下:

1.select 名称,单位,sum(金额) as 金额 into table1_tmp from table1 group by 名称,单位
2.truncate table table1
3.insert into table1 select * from table1_tmp
4.drop table1_tmp
第4个回答  2008-04-11
SELECT MIN(编号),学号,姓名,SUM(成绩)
FROM 成绩表
GROUP BY 学号,姓名
ORDER BY MIN(编号)

出来的编号是
1
3
6
6
第5个回答  2008-04-11
SELECT MIN(编号),学号,姓名,SUM(成绩) FROM 成绩表
GROUP BY 学号,姓名
ORDER BY MIN(编号);
相似回答