【问题标题】:Equivalent of MSSQL with statement in MYSQLMSSQL 与 MYSQL 中的语句等价
【发布时间】:2014-07-01 15:05:02
【问题描述】:

mysql中是否有与下面语句等效的语句?

With Tmp1 as (
        Select Distinct EmpID, TypeID 
        From tb_deductionBalance
), Tmp2 as (
    Select *,
       row_number() OVER ( order by empID /* no employeeID in Tmp1 */) as RowNum 
    From Tmp1
)
Select * From Tmp2
Where RowNum Between @Start and @End

我必须将一个 mssql 数据库迁移到 mysql,并且有很多这样的语句,如果无法翻译,在 mysql 中重新创建需要更多时间。

谢谢

【问题讨论】:

  • MySQL 不支持common table expressions。相反,您必须使用子查询。也不支持row_number等解析函数——你必须自己写。
  • @sgeddes,这正是 OP 所要求的,MSSQL 与 MYSQL 中的语句等效
  • @astander -- 我编辑了我的评论。 OP 可以改用子查询。

标签: mysql sql-server database-migration


【解决方案1】:
SELECT DISTINCT EmpID, TypeID
FROM tb_deductionBalance
ORDER BY empID
LIMIT YourStartNumber - 1, YourEndNumber - YourStartNumber

很遗憾,您不能在 LIMIT 中使用变量,因此您需要在此处使用实际整数。例如,如果您想要第 3 到 10 行的结果,则需要使用:

SELECT DISTINCT EmpID, TypeID
FROM tb_deductionBalance
ORDER BY empID
LIMIT 2, 7

【讨论】:

    猜你喜欢
    • 2012-05-04
    • 2018-07-29
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 2022-08-03
    • 2013-12-01
    • 2015-05-14
    • 1970-01-01
    相关资源
    最近更新 更多