ROW_NUMBER()OVER(通过在mysql5.7中给出语法错误进行部分设置

时间:2020-04-08 09:28:41

标签: mysql select partition-by

我正在使用partition by获取重复的行,并且此查询在mysql5.7中返回语法错误

select column1,ROW_NUMBER() OVER (PARTITION BY column2, column3 ORDER BY column2 DESC) as  RowNumber 
from tableA

错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY column1, column2 ' at line 1

或其他任何查询

或者其他任何查询可重新运行仅重复的行(第2列和第3列分别包含相同的值),在这种情况下,输出将返回第1、3、5、6行

表中的所有行:All rows in table

查询所需的输出:Desired output by query

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

具有EXISTS:

select t.* from tablename t
where exists (
  select 1 from tablename
  where column1 <> t.column1 and column2 = t.column2 and column3 = t.column3
)