hql的rank函数,select中的select导致antlr异常

发布于 2024-10-20 07:27:20 字数 1295 浏览 1 评论 0原文

我试图使以下 hql 查询工作,但没有成功。我试图根据表单中的字段值找出特定用户的排名。在 SQL 中这非常有效。

SELECT tmp.rang
    FROM (
          SELECT    b.ID as user, rank() as rang OVER (ORDER BY frh.Wert) 

          FROM      EKB.KennzahlenManagement.FormularResultHistorie as frh
          JOIN      frh.Formular_Bogen_K_Feld  fbkFeld
          JOIN      frh.Formular_Gesendent.Benutzer b

          WHERE     fbkFeld.FormularBogen.ID =:formularBogenId
          AND       fbkFeld.ResultFlag = 1
          AND       frh.Formular_Gesendent.Eingabe_nummer IN 
                                        (SELECT MAX(tmp.Eingabe_nummer) 
                                         FROM EKB.KennzahlenManagement.Formular_gesendet tmp
                                         WHERE tmp.Benutzer.ID = frh.Formular_Gesendent.Benutzer.ID 
                                         AND tmp.Formular.ID = frh.Formular_Gesendent.Formular.ID
                                         GROUP BY tmp.Benutzer
                                        )
    ) as tmp
    WHERE   tmp.usr =:userId 

到目前为止,我已经发现了两个问题。

1)由于第二次选择,我得到“NHibernate.Hql.Ast.ANTLR.QuerySyntaxException:抛出了'Antlr.Runtime.NoViableAltException'类型的异常。近行...”。我该如何解决这个问题?有什么解决方法吗?

2)rank()函数似乎有问题。我也遇到了与上面类似的异常。 HQL中没有rank()吗?如果有的话可以举个例子吗?

I'm trying to make the following hql query work, but with no success. I'm trying to find out what rank has a specific user, dependent on a field value in a form. In SQL this works great.

SELECT tmp.rang
    FROM (
          SELECT    b.ID as user, rank() as rang OVER (ORDER BY frh.Wert) 

          FROM      EKB.KennzahlenManagement.FormularResultHistorie as frh
          JOIN      frh.Formular_Bogen_K_Feld  fbkFeld
          JOIN      frh.Formular_Gesendent.Benutzer b

          WHERE     fbkFeld.FormularBogen.ID =:formularBogenId
          AND       fbkFeld.ResultFlag = 1
          AND       frh.Formular_Gesendent.Eingabe_nummer IN 
                                        (SELECT MAX(tmp.Eingabe_nummer) 
                                         FROM EKB.KennzahlenManagement.Formular_gesendet tmp
                                         WHERE tmp.Benutzer.ID = frh.Formular_Gesendent.Benutzer.ID 
                                         AND tmp.Formular.ID = frh.Formular_Gesendent.Formular.ID
                                         GROUP BY tmp.Benutzer
                                        )
    ) as tmp
    WHERE   tmp.usr =:userId 

So far I have identified two problems.

1) I get "NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line..." because of the second select. How can I solve this problem? Any workarounds?

2) There seems to be something wrong with the rank() function. I'm also getting a similar exception like the one above. Is there no rank() in HQL? If there is, can you please give an example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

情独悲 2024-10-27 07:27:20

据我所知,RANK()目前在NHibernate中还没有实现。您可能想尝试将其注册为方言中的自定义函数。 这是一个帮助您入门的示例。由于其语法原因,注册 RANK 可能比示例更复杂。

As far as I know, RANK() is not currently implemented in NHibernate. You might want to try registering it as a custom function in the dialect. Here's an example to get you started. Registering RANK will probably be more complex than the example because of its syntax.

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