在连接中选择

发布于 2024-11-27 03:01:55 字数 971 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

又怨 2024-12-04 03:01:55

我不相信 UPDATE 语法中允许使用 FROM

I don't believe FROM is allowed in the UPDATE syntax.

只有影子陪我不离不弃 2024-12-04 03:01:55

您无法更新别名,您需要指定表名。

You can't update an alias, you need to have the table name specified.

傾旎 2024-12-04 03:01:55

作为对其他答案的补充,H2 的 UPDATE 中不允许 JOIN (就像 FROM)。它在子查询中是允许的。

本质上,坚持基本语法:

UPDATE SomeTable as SomeAlias
 SET SomeField = ?
 WHERE (%GoWild%)

是否需要别名取决于您的 where 子句。

参考:http://www.h2database.com/html/grammar.html#update

Complementary to other answers, JOIN (just as FROM) is not allowed in UPDATE for H2. It would be allowed in a sub query.

Essentially, stick to the basic syntax:

UPDATE SomeTable as SomeAlias
 SET SomeField = ?
 WHERE (%GoWild%)

Whether or not you need the alias is up to your where clause.

Reference: http://www.h2database.com/html/grammar.html#update

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文