赞
踩
select p.* ,row_number()over(partition by p.code order order by a.id desc) as row_index from t_pi_part p;
班级信息
NAME CLASS S
fda 1 80
ffd 1 78
dss 1 95
cfe 2 74
gds 2 92
gf 3 99
ddd 3 99
adf 3 45
asdf 3 55
3dd 3 78
通过:
select * from
(
select name,class,s,rank()over(partition by class order by s desc) mm from t2
)
where mm=1
得到结果:
NAME CLASS S MM
dss 1 95 1
gds 2 92 1
gf 3 99 1
ddd 3 99 1
注意:
将B栏位值相同的对应的C 栏位值加总
表结构:
A B C
1 1 1
1 2 2
1 3 3
2 2 5
3 4 6
通过
select a,b,c, SUM(C) OVER (PARTITION BY B) C_Sum
from test
得到结果
A B C C_SUM
1 1 1 1
1 2 2 7
2 2 5 7
1 3 3 3
3 4 6 6
如果不需要已某个栏位的值分割,那就要用 null
select a,b,c, SUM(C) OVER (PARTITION BY null) C_Sum
from test
例如:对于以下列
aa
1
2
2
2
3
4
5
6
7
9
通过
sum(aa)over(order by aa range between 2 preceding and 2 following)
得出的结果是
AA SUM
1 10
2 14
2 14
2 14
3 18
4 18
5 22
6 18
7 22
9 9
sum(sale) OVER
(ORDER BY aa ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
AS SUM
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。