简单举例:
SELECT code,kpi_type,plan_value_num,
row_number()over(partition by code,kpi_type order by plan_value_num desc)rowno FROM fs_target_yp_kpi
分析:
code,kpi_type,plan_value_num 记录后面开窗函数后的规律值
partition by code,kpi_type 按照这两列分组
order by plan_value_num desc 按照此字段降序排序
row_number() 记录每组排序后编号
http://blog.itpub.net/27042095/viewspace-768880/
其它:
decode()用法
SELECT ID,DECODE(inParam,'beComparedParam','值1' ,'值2') name FROM bank
解读:
如果第一个参数inParam=='beComparedParam',则select得到的name显示为值1,
如果第一个参数inParam!='beComparedParam',则select得到的name显示为值2
https://www.cnblogs.com/jinzhiming/p/5381812.html
补充:
select *,row_number()over(partition by region_grade order by parent_region_code,region_code) from lbs_region_code_tbl where
parent_region_code='12'
查询二级机构下面的三级机构
select
*,
row_number() over(
partition by region_grade
order by
parent_region_code,
region_code
)
from
lbs_region_code_tbl
where region_grade='3' and parent_region_code in (select region_code from lbs_region_code_tbl where parent_region_code in ('1') and region_grade='2'
and region_code='12')
查询二级机构下面的三级机构
select c.um_no,c.name,a.region_code,a.description,b.dept_code from lbs_region_code_tbl a,sws_fs_dept b,sws_fs_user c where a.region_code=b.region_code and b.dept_code=c.dept_code
and c.um_no='WUJIANGLIU345'
查询人员下面的区域码和部门编码