Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySql中CTE的替代方案_Mysql_Sql_Sql Server_Common Table Expression - Fatal编程技术网

MySql中CTE的替代方案

MySql中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

我在TSQL中有创建树的代码,但我很困惑:如何将其转换为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)  

MySQL的可能副本无法执行递归查询。您需要编写一个递归调用自身的存储过程