sql-使用铅与组通过以获取组的最接值

发布于 2025-01-26 11:20:52 字数 1699 浏览 3 评论 0原文

我想使用铅函数来获取组的最接近值
一些示例数据。

主题代码等级以下是来自 flx_alps_boundaries
20 bd-ac-al11.12
20-bd-ac-al21.03
20 bd-ac-al30.97
20 bd-ac ac ac的 -AL40.92
20-BD-AC-AL50.86
20-BD-AC-AL60.84
20-BD-AH-AL11.15
20-BD-AH-AL21.10
20-BD-AH-AL31.05
20 20 -bd-ah-al41.00
20-bd-ah-al50.98
20 bd-ah-al60.96

i是使用公式计算主题的分数,并从上表中获得最接近的匹配分数。例如,如果受试者为20 bd-ac-al得分为0.95,则等级应为4

这是我当前的SQL

   select top 1 
          ab.alps_grade  as alps_grade,
          round( sum (actual_alps_points - expected_alps_points) 
                   / (count(reference) * 100)  + 1,2 ) as alps_score
   from   alps_cte 
   inner join [flx_alps_boundaries] ab 
           on alps_cte.course = ab.course_code
   where  ab.course_code in ('20-BD-AC-AL','20-BD-AH-AL')
   group by course,ab.alps_grade,ab.alps_score
   order by abs(round(sum(actual_alps_points 
                       - expected_alps_points) 
                       / (count(reference)*100)  + 1, 2) 
                       - ab.alps_score)

此查询仅返回一行。我如何使用铅来获得适当的等级每个 受试者的分数?

I would like to use the Lead function to get the closest value for a group
Below is some sample data from flx_alps_boundaries

Subject codeGradeScore
20-BD-AC-AL11.12
20-BD-AC-AL21.03
20-BD-AC-AL30.97
20-BD-AC-AL40.92
20-BD-AC-AL50.86
20-BD-AC-AL60.84
20-BD-AH-AL11.15
20-BD-AH-AL21.10
20-BD-AH-AL31.05
20-BD-AH-AL41.00
20-BD-AH-AL50.98
20-BD-AH-AL60.96

I am calculating the score for a subject using a formula and getting the grade for the nearest matching score from the above table . eg if score is 0.95 for subject 20-BD-AC-AL the grade should be 4

This is my current sql

   select top 1 
          ab.alps_grade  as alps_grade,
          round( sum (actual_alps_points - expected_alps_points) 
                   / (count(reference) * 100)  + 1,2 ) as alps_score
   from   alps_cte 
   inner join [flx_alps_boundaries] ab 
           on alps_cte.course = ab.course_code
   where  ab.course_code in ('20-BD-AC-AL','20-BD-AH-AL')
   group by course,ab.alps_grade,ab.alps_score
   order by abs(round(sum(actual_alps_points 
                       - expected_alps_points) 
                       / (count(reference)*100)  + 1, 2) 
                       - ab.alps_score)

This query only returns one row. How do I use LEAD to get the appropriate grade for each
subject's score?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文