在连接中选择
我在 H2 中查询
UPDATE THD
SET RepostFlag = 'Y'
,RunListNoRetroPolicyPrepay = ?
,RetroObject = ?
FROM TranHead AS THD
JOIN (
SELECT CustPolicyNo AS CustPolicyNo
,MIN(PremPeriod) AS PremPeriod
FROM TranHead
WHERE RepostFlag = 'Y'
AND PayoutTypeNo = ?
GROUP BY CustPolicyNo
) AS THDToBeReposted ON THD.CustPolicyNo = THDToBeReposted.CustPolicyNo
WHERE THD.RepostFlag = 'N'
AND THD.PremPeriod > THDToBeReposted.PremPeriod
失败,并显示以下消息
未找到表“THD”;
我查看了 http://www.h2database.com/html/grammar.html#table_expression 查看H2是否支持join中的select。看来确实如此。也许我在查看语法时遗漏了一些东西,但在我看来,查询应该在 H2 中工作。
有人看到出了什么问题吗?
谢谢。
I have query
UPDATE THD
SET RepostFlag = 'Y'
,RunListNoRetroPolicyPrepay = ?
,RetroObject = ?
FROM TranHead AS THD
JOIN (
SELECT CustPolicyNo AS CustPolicyNo
,MIN(PremPeriod) AS PremPeriod
FROM TranHead
WHERE RepostFlag = 'Y'
AND PayoutTypeNo = ?
GROUP BY CustPolicyNo
) AS THDToBeReposted ON THD.CustPolicyNo = THDToBeReposted.CustPolicyNo
WHERE THD.RepostFlag = 'N'
AND THD.PremPeriod > THDToBeReposted.PremPeriod
fails in H2 with following message
Table "THD" not found;
I looked at http://www.h2database.com/html/grammar.html#table_expression to see if H2 supports selects in join. It appears it does. Maybe I am missing something when looking at the grammar, but it seems to me that the query should work in H2.
Anyone see what is wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不相信
UPDATE
语法中允许使用FROM
。I don't believe
FROM
is allowed in theUPDATE
syntax.您无法更新别名,您需要指定表名。
You can't update an alias, you need to have the table name specified.
作为对其他答案的补充,H2 的
UPDATE
中不允许JOIN
(就像FROM
)。它在子查询中是允许的。本质上,坚持基本语法:
是否需要别名取决于您的 where 子句。
参考:http://www.h2database.com/html/grammar.html#update
Complementary to other answers,
JOIN
(just asFROM
) is not allowed inUPDATE
for H2. It would be allowed in a sub query.Essentially, stick to the basic syntax:
Whether or not you need the alias is up to your where clause.
Reference: http://www.h2database.com/html/grammar.html#update