MySql中CTE的替代品

时间:2013-11-15 12:45:55

标签: mysql sql sql-server common-table-expression

我在SQL中创建了一个用于创建树的代码,但我很困惑:如何将其转换为mysql ...

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)  

0 个答案:

没有答案