sql转换成hql报错。。。。?

unexpected token: ( near line 1, column 59 [from com.esoft.archer.user.model.UserBill bill inner join (select user.id,max(seqNum) as seq from com.esoft.archer.user.model.UserBill group by user.id)tmp where bill.user.id=tmp.user.id and bill.seqNum=tmp.seq order by bill.user.id]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 59 [from com.esoft.archer.user.model.UserBill bill inner join (select user.id,max(seqNum) as seq from com.esoft.archer.user.model.UserBill group by user.id)tmp where bill.user.id=tmp.user.id and bill.seqNum=tmp.seq order by bill.user.id]

5个回答

贴一下hql看看,报错看不懂

u010369832
小-强 from UserBill bill inner join (select user.id,max(seqNum) as seq from UserBill group by user.id)tmp where bill.user.id=tmp.user.id and bill.seqNum=tmp.seq order by bill.user.id
4 年多之前 回复

贴源码,别贴报错。,贴报错,谁能看懂

u010369832
小-强 from UserBill bill inner join (select user.id,max(seqNum) as seq from UserBill group by user.id)tmp where bill.user.id=tmp.user.id and bill.seqNum=tmp.seq order by bill.user.id
4 年多之前 回复

你的hql应该是
from UserBill bill inner join (select user.id,max(sqlNum) as seq from UserBill group by user.id)**tmp** where bill.user.id=tmp.user.id and bill.seqNum=tmp.seq order by bill.user.id

tmp前面加个空格看看。。 还有 where改成on看看,上面加粗的地方哦

u010369832
小-强 不行啊,还是报这个错。[ERROR] [http-bio-8080-exec-9] [02:10:17] org.hibernate.hql.PARSER - line 1:59: unexpected token: ( [ERROR] [http-bio-8080-exec-9] [02:10:17] org.hibernate.hql.PARSER - line 1:75: unexpected token: max [ERROR] [http-bio-8080-exec-9] [02:10:17] org.hibernate.hql.PARSER - line 1:59: unexpected token: ( [ERROR] [http-bio-8080-exec-9] [02:10:17] org.hibernate.hql.PARSER - line 1:75: unexpected token: max
4 年多之前 回复

源码:from UserBill bill inner join (select user.id,max(seqNum) as seq from UserBill group by user.id)tmp where bill.user.id=tmp.user.id and bill.seqNum=tmp.seq order by bill.user.id

你给的hql不完整啊。首先 join 之后应该用 on,而不是用 where,这个不会报错。
但是tmp子查询里,怎么会有 user.id 这样的查询?最后在执行 order by 时,被排序的字段不应该是有别名的,因为执行 order by 时,select 已经执行结束了,所以它应该是有个列名。
我觉得你应该想要的样子是这样。

 select bill.id as id, bill.seqNum as seqNum
from (
    select id, seqNum
    from UserBill
) bill join (
    select id, max(seqNum) as seq
    from UserBill
    group by id
) tmp on(bill.id = tmp.id and bill.seqNum = tmp.seq)
order by id

逻辑上也没看明白你想要做什么,但是语法上这样就对了。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问