【问题标题】:Trying hard to solve error 1064努力解决错误1064
【发布时间】:2014-01-05 05:02:50
【问题描述】:

我已经努力但没有得到下面的解决方案..请帮助!!

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):您的 SQL 语法有错误;检查手册
对应于您的 MySQL 服务器版本,以便在 'Group 附近使用正确的语法
InMainGroup (accountGroupId,HierarchyLevel) AS
(
选择 accountGroupId,
1 a' 在第 6 行

【问题讨论】:

  • MySQL 不支持公用表表达式。您需要升级到允许它们的 DBMS。

标签: mysql sql stored-procedures common-table-expression


【解决方案1】:

您似乎正在尝试使用 MySQL 不支持的 CTE(在撰写本文时)。

大多数版本的 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 ; //

【讨论】:

  • 谢谢.. 但你错过了;在第 16 行结束之前。 +5 给你
猜你喜欢
  • 1970-01-01
  • 2015-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多