查找学生的排名 -Sql Compact

发布于 2024-09-03 06:02:06 字数 474 浏览 2 评论 0原文

我有一个这样的表:

Name Mar1 Mar2 Mar3 Total

xxx 80 80 80 240

yyy 60 70 50 180

aaa 85 65 75 225

我想根据总计找到学生的排名。我使用 SQL Compact 3.5 。由于我们在sql server中有rank()函数,我们是否有可以找到学生排名的东西???当我使用“选择总计,排名()超过(按总描述排序)i1 来自 stmarks “它给出的错误为

” 主要错误 0x80040E14,次要错误 25501

选择 Total,rank() over(按总描述排序)i1 来自stmarks 解析查询时出错。 [ 令牌行号 = 1,令牌行偏移 = 21,错误令牌 = 结束 ] ”

Sql Compact是否支持rank()或者还有其他方法吗???

I have a table like this :

Name Mar1 Mar2 Mar3 Total

xxx 80 80 80 240

yyy 60 70 50 180

aaa 85 65 75 225

I wanted to find the rank of the student based on total. I using SQL Compact 3.5 . As we have rank() function in sql server do we have something with which we can find the students rank??? When I used "select Total,rank() over (order by total desc) i1
from stmarks " it's giving error as

"
Major Error 0x80040E14, Minor Error 25501

select Total,rank() over (order by total desc) i1
from stmarks
There was an error parsing the query. [ Token line number = 1,Token line offset = 21,Token in error = over ]
"

Do Sql Compact support rank() over or is there any another way???

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美的太阳 2024-09-10 06:02:06

根据搜索结果,over() 似乎不适用于 sql-compact。因此,我尝试了此处中的自连接概念。只是我修改了查询,以便它可以正确处理重复值。删除等号。修改后的查询是:

SELECT a1.Name, a1.Total, COUNT(a2.Total) Rank
  FROM StMarks a1, StMarks a2
 WHERE a1.Total < a2.Total or (a1.Total=a2.Total and a1.Name = a2.Name)
GROUP BY a1.Name, a1.Total
ORDER BY a1.Total DESC, a1.Name DESC;

它现在工作得很好。

According to the search result it seems over() doesn't work with sql-compact. So I tried the self join concept as in here. Just I modified the query so that it works with duplicate values properly . Remove the equal to sign. The modified query is :

SELECT a1.Name, a1.Total, COUNT(a2.Total) Rank
  FROM StMarks a1, StMarks a2
 WHERE a1.Total < a2.Total or (a1.Total=a2.Total and a1.Name = a2.Name)
GROUP BY a1.Name, a1.Total
ORDER BY a1.Total DESC, a1.Name DESC;

It works great rite now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文