我已经努力了,但没有得到以下解决方案.. plz help !!
CREATE PROCEDURE AccountLedgerViewUnderBank()
begin
WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS
(
select accountGroupId,
1 as HierarchyLevel
from tbl_AccountGroup where accountGroupId='9'
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'
FROM tbl_AccountLedger
where accountGroupId IN (select accountGroupId from GroupInMainGroup
)
end ; //
显示错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group InMainGroup (accountGroupId,HierarchyLevel) AS ( select accountGroupId, 1 a' at line 6
答案 0 :(得分:2)
看起来你正在尝试使用CTE,而MySQL不支持(在撰写本文时)。
大多数MySQL版本都支持子查询,因此您可以将其重写为:
CREATE PROCEDURE AccountLedgerViewUnderBank()
begin
SELECT ledgerId AS 'Account Ledger Id',
acccountLedgerName AS 'Account Ledger Name'
FROM tbl_AccountLedger
where accountGroupId
IN (select accountGroupId
from tbl_AccountGroup where accountGroupId='9'
UNION ALL
select e.accountGroupId
from tbl_AccountGroup as e,GroupInMainGroup G
where e.groupUnder=G.accountGroupId)
end ; //