我有一个错误的查询,但是我找不到错误。

huangapple 未分类评论44阅读模式
英文:

I have an incorrect Query but I am not able to find the error

问题

Code:

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills) WHERE `UUID` = ?

Error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `UUID` = '37bb2c2c-e170-469c-a08e-6a22e7d083cd'' at line 1
英文:

Code:

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills) WHERE `UUID` = ?

Error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `UUID` = '37bb2c2c-e170-469c-a08e-6a22e7d083cd'' at line 1

I have no idea how to fix the error, because I dont know the error.

答案1

得分: 0

如果您想从子查询中获取所有列,则不需要外部查询:

SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills WHERE `UUID` = ?

如果您想保持原样,必须对子查询进行别名处理:

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills) t WHERE `UUID` = ?
英文:

If you want all the columns from the subquery then you don't need the outer query:

SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills WHERE `UUID` = ?

If you want to keep it as it is you must alias the subquery:

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills) t WHERE `UUID` = ?

huangapple
  • 本文由 发表于 2020年4月9日 01:49:17
  • 转载请务必保留本文链接:https://java.coder-hub.com/61106884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定