我有桌子
name quentity
pramo 1000
ladkat 2000
我想选择输出作为总和的新行
name quentity
pramod 1000
ladkat 2000
total 3000
大多数数据库都支持rollup
或的某些版本grouping sets
。例如:
select coalesce(name, 'Total') as name, sum(quantity) as quantity
from t
group by name with rollup;
或者:
select coalesce(name, 'Total') as name, sum(quantity) as quantity
from t
group by grouping sets ((name), ()) ;
请注意,它们与聚合查询一起使用,因此您需要一个group by
子句。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句