【问题标题】:ROW_NUMBER() OVER (PARTITION BY giving Syntax error in mysql5.7ROW_NUMBER() OVER (PARTITION 通过在 mysql 5.7 中给出语法错误
【发布时间】:2020-04-08 09:28:41
【问题描述】:

我正在使用 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 行

表中的所有行:

查询所需的输出:

感谢您的帮助。

【问题讨论】:

  • MySql 5.7 不支持窗口函数
  • @forpas 谢谢,你能解释一下哪个是窗口函数吗?
  • ROW_NUMBER() 是一个窗口函数。
  • @forpas 获取重复值行的任何其他解决方案(也希望选择中包含唯一值的 id)
  • 发布样本数据和预期结果以澄清。

标签: mysql select partition-by


【解决方案1】:

存在:

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

【讨论】:

  • 感谢您的帮助。如果我想跳过重复的第一行,那么我需要在此查询中进行哪些修改?假设有 2 行重复,那么我只想获得第二行,如果 3 则想通过先跳过获得最后 2 行。谢谢
  • 类似:select t.* from tablename t where t.column1 &gt; (select min(column1) from tablename where column2 = t.column2 and column3 = t.column3)
  • 非常感谢您的及时回复
猜你喜欢
  • 2018-10-16
  • 1970-01-01
  • 2021-03-03
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
  • 2018-07-25
  • 1970-01-01
  • 2013-02-24
相关资源
最近更新 更多