oracle分析函数
1.sum 求和与其他字段的混合写法
表名:testtable
字段 cop_cd,sik_cd,su1,su2
要求检索出字段cop_cd,sik_cd,su1的总和,su2的总和
一般方法用的sum要进行分组,不能一次进行检索,现改用over( partition by)
select *
from
(
select cop_cd,
sik_cd,
sum(su1) over (partition by sik_cd),
sum(su2) over (partition by sik_cd),
row_number() over (partition by sik_cd order by sik_cd) as rn
from testtable
where ....
)
where rn=1
2.min 最小值与其他字段的混合写法
SELECT
MIN(TRUNC((NVL(a.e,0)-NVL(a.d,0))/NVL(b.c,0))) over() AS aaa,
c.cd AS bbb
FROM a,b,c