hql rank function, select in select causes antlr exception
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?
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.
精彩评论