hql的rank函数,select中的select导致antlr异常
我试图使以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,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.