MySql中CTE的替代方案
我在TSQL中有创建树的代码,但我很困惑:如何将其转换为mysqlMySql中CTE的替代方案,mysql,sql,sql-server,common-table-expression,Mysql,Sql,Sql Server,Common Table Expression,我在TSQL中有创建树的代码,但我很困惑:如何将其转换为mysql CREATE PROCEDURE AccountLedgerViewUnderSundryDebtorCreditorCash AS WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS ( select accountGroupId, 1 as HierarchyLevel from tbl_AccountGroup where acco
CREATE PROCEDURE AccountLedgerViewUnderSundryDebtorCreditorCash
AS
WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS
(
select accountGroupId,
1 as HierarchyLevel
from tbl_AccountGroup where accountGroupId='27'or accountGroupId = '28'or accountGroupId = '11'
UNION ALL
select e.accountGroupId,
G.HierarchyLevel + 1 AS HierarchyLevel
from tbl_AccountGroup as e,GroupInMainGroup G
where e.groupUnder=G.accountGroupId
)
SELECT
ledgerId AS [Account Ledger Id],
acccountLedgerName AS [Account Ledger Name],
accountGroupId AS [Account Group Id],
openingBalance AS [Opening Balance],
debitOrCredit AS [Credit Or Debit],
defaultOrNot AS [Editable Or Not],
description AS [Description]
FROM tbl_AccountLedger
where accountGroupId IN (select accountGroupId from GroupInMainGroup)
MySQL的可能副本无法执行递归查询。您需要编写一个递归调用自身的存储过程