我有一种情况,在临时表中插入多个数据集。最后,我想在temp表的所有行中显示这些多个数据集的总行数。例如:
cnt1 name age
300 peter 21
200 piper 22期望的结果集:
cnt1 name age
500 peter 21
500 piper 22这是我在一个非常长的存储过程的末尾所寻找的结果。我无法搞清楚如何在一列上加起来,并在所有行中显示和。
发布于 2015-06-11 16:37:05
具有窗口功能:
select sum(cnt1) over() as cnt1, name, age
from TableName编辑:
select (select sum(distinct cnt1) from TableName) as cnt1, name, age
from TableName发布于 2015-06-11 16:36:40
尝试这样做(如果需要,可以使用union all将其附加到先前的结果中)。
Select sum(Cnt1) over () as Cnt1, name, age
from MyTable我的答案最初使用的是over (partition by 1),但我认为这是不必要的。
发布于 2015-06-11 16:37:28
使用返回总计的子查询交叉连接:
select gt cnt1, name, age
from mytable
cross join (select sum(cnt1) gt from mytable) xhttps://stackoverflow.com/questions/30786480
复制相似问题