Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

sql - I am trying to provide a ranking based on a previous partition

I am trying to change the ranking column where instead of ordering by RMSE ASC I want to order by RMSESum ASC (which was a previous partition by)….when I do this I get an error that "ordered analytic functions cannot be nested" any idea around this?

Select material, plant, fiscper, dmd_final_Fcst, sum_final_dmd_qty, 
row_number() Over (partition by material, plant order by **RMSE ASC**) as **Ranking**,
Sum(RMSE) over (partition by material, plant) as **RMSESum**,
Power(Fcst_er,2) As Sq_er,
dmd_final_fcst - sum_final_dmd_qty As Fcst_Er,
Sqrt(MSE) As RMSE,
Avg(Sq_er) as MSE 
from PRD_DWH_PURCHASING.HistoricalForecastVal
group by 1,2,3,4,5;
question from:https://stackoverflow.com/questions/65517176/i-am-trying-to-provide-a-ranking-based-on-a-previous-partition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should use the sub-query as follows:

SELECT T.*,
       row_number() Over (partition by material, plant order by RMSESum ASC) as Ranking
FROM
(Select material, plant, fiscper, dmd_final_Fcst, sum_final_dmd_qty,
       Sum(RMSE) over (partition by material, plant) as RMSESum,
       Power(Fcst_er,2) As Sq_er,
       dmd_final_fcst - sum_final_dmd_qty As Fcst_Er,
       Sqrt(MSE) As RMSE,
       Avg(Sq_er) as MSE
  from PRD_DWH_PURCHASING.HistoricalForecastVal
 group by 1,2,3,4,5) t;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...