更新排名列时遇到问题
我对MySQL的了解是通过PHP更新选择删除安装。我用谷歌搜索了这个并转到 Stack Overflow 搜索词是 MySQL 排名更新。我发现的那些可以帮助我的。告诉他们如何解决问题的人。告诉他们通过选择而不是更新来做到这一点,甚至向他们展示如何做到这一点。
我知道如何通过选择谷歌教我来做到这一点。
我需要通过更新来做到这一点。
表和查询如下。
表
region_id | pstrank | 101 |
---|---|---|
101 | 20 | 1 |
101 | 19 | 2 |
101 | 19 | 2 |
。 | 15 | 4 |
100 | 20 | 1 |
100 | 13 | 2 |
查询
UPDATE `test1`
SET `rank` =
RANK() OVER(PARTITION BY `region_id` ORDER BY `pst` DESC)
当我运行此代码时,出现此错误 窗口函数仅允许在 SELECT 列表和 ORDER BY 子句中使用。
您能告诉我如何解决这个问题吗?
感谢您的提前帮助
My knowledge in MySQL is updating select deleting installing through PHP. I googled this and went to Stack overflow search terms were MySQL rank update. The ones I found that could help me. The persons that told them how to fix it. Told them do it through a select not an update, and even show them how to do it.
I know how to do it through a select Google taught me that.
I need to do it through an update.
Table and query are down below.
Table
region_id | pst | rank |
---|---|---|
101 | 20 | 1 |
101 | 19 | 2 |
101 | 19 | 2 |
101 | 15 | 4 |
100 | 20 | 1 |
100 | 13 | 2 |
Query
UPDATE `test1`
SET `rank` =
RANK() OVER(PARTITION BY `region_id` ORDER BY `pst` DESC)
When I run this code, I get this error.
Window function is allowed only in SELECT list and ORDER BY clause.
Can you please show me how to fix this issue?
Thank you for your help in advanced
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将表连接到返回排名的查询:
请参阅 演示< /a>.
You need a join of the table to a query that returns the ranks:
See the demo.