DB2 增加排序行号


行号函数

ROW_NUMBER() OVER (ORDER BY 字段名) AS NUMBER

实际例子保留
select a.* from (
select ROW_NUMBER() OVER (ORDER BY case when  a.parent_kpi_id is null then b.kpi_value else 0 end desc) AS NUMBER,c.kpi_id,c.kpi_name,b.kpi_value,b.bgq,b.cbfybs,b.cbftbs,b.cbsptbs,b.cbrbs,b.report_id 
from JXKH.REPORT_KPI_REALATION a 
left join jxkh.kpi_value_2954 b on a.kpi_id = b.kpi_id  and a.report_id = b.report_id and b.bgq=2012062020120719 
left join jxkh.kpi_base_info c on c.kpi_id = a.kpi_id 
where a.report_id = 11022 and b.cbsptbs is not null and b.cbrbs is null 
and (a.parent_kpi_id = (select kpi_id from JXKH.REPORT_KPI_REALATION where parent_kpi_id is null and report_id = 11022) or a.parent_kpi_id is null)
) a  where cbsptbs = 29540099

猜你喜欢

转载自piranha.iteye.com/blog/1605183
db2