Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 正在努力解决错误1064_Mysql_Sql_Stored Procedures_Common Table Expression - Fatal编程技术网

Mysql 正在努力解决错误1064

Mysql 正在努力解决错误1064,mysql,sql,stored-procedures,common-table-expression,Mysql,Sql,Stored Procedures,Common Table Expression,我已经尽力了,但没有得到下面的解决方案。。请帮忙 CREATE PROCEDURE AccountLedgerViewUnderBank() begin WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS ( select accountGroupId, 1 as HierarchyLevel from tbl_AccountGroup where accountGroupId='9' UNION ALL select e.ac

我已经尽力了,但没有得到下面的解决方案。。请帮忙

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 错误1064(42000):您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便在“组”附近使用正确的语法 在单组(accountGroupId,HierarchyLevel)中作为 ( 选择accountGroupId, 6号线1 a'
看起来您正在尝试使用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 ; //

MySQL不支持常用的表表达式。您需要升级到允许它们的DBMS。谢谢。但是您错过了;在第16行结束之前。+5到u