将Sql server查询转换为MySql查询

时间:2016-08-04 09:36:59

标签: mysql sql-server

我正在尝试将Query从sql server转换为MySql。我在Sql中的查询如下:

WITH ChildCategories (ParentID, categoryID, Level)
AS
(
    SELECT e.ParentID, e.CategoryID, 0 AS Level
    FROM dbo.Category AS e
    WHERE ParentID=195
    UNION ALL
    SELECT e.ParentID, e.CategoryID, Level + 1
    FROM dbo.Category AS e
    INNER JOIN ChildCategories AS d
        ON e.ParentID = d.categoryID
)
Select 195 as categoryID
UNION 
select CategoryID from ChildCategories

我尝试在MySql中转换上面的查询,如下所示:

select CategoryID, Name,( @pv:=t.ParentID,t.CategoryID) as ParentID 
    from (select CategoryID, Name, ParentID from Category order by CategoryID     desc) t 
    join (select @pv:=196)tmp on t.CategoryID=@pv 
    order by ParentID;

但是我收到了这个错误:

Operand should contain 1 column(s)

有人可以帮忙吗?提前谢谢。

0 个答案:

没有答案