sql-使用铅与组通过以获取组的最接值
我想使用铅函数来获取组的最接近值
一些示例数据。
主题代码 | 等级 | 以下是来自 flx_alps_boundaries |
---|---|---|
20 bd-ac-al | 1 | 1.12 |
20-bd-ac-al | 2 | 1.03 |
20 bd-ac-al | 3 | 0.97 |
20 bd-ac ac ac的 -AL | 4 | 0.92 |
20-BD-AC-AL | 5 | 0.86 |
20-BD-AC-AL | 6 | 0.84 |
20-BD-AH-AL | 1 | 1.15 |
20-BD-AH-AL | 2 | 1.10 |
20-BD-AH-AL | 3 | 1.05 |
20 20 -bd-ah-al | 4 | 1.00 |
20-bd-ah-al | 5 | 0.98 |
20 bd-ah-al | 6 | 0.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 code | Grade | Score |
---|---|---|
20-BD-AC-AL | 1 | 1.12 |
20-BD-AC-AL | 2 | 1.03 |
20-BD-AC-AL | 3 | 0.97 |
20-BD-AC-AL | 4 | 0.92 |
20-BD-AC-AL | 5 | 0.86 |
20-BD-AC-AL | 6 | 0.84 |
20-BD-AH-AL | 1 | 1.15 |
20-BD-AH-AL | 2 | 1.10 |
20-BD-AH-AL | 3 | 1.05 |
20-BD-AH-AL | 4 | 1.00 |
20-BD-AH-AL | 5 | 0.98 |
20-BD-AH-AL | 6 | 0.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论