u010369832
小-强
采纳率0%
2016-03-03 10:08 阅读 1.5k

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条回答 默认 最新

  • princess4426 另一只蝴蝶 2016-03-03 10:25

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

    点赞 评论 复制链接分享
  • haoxin1210 haoxin1210 2016-03-03 14:37

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

    点赞 评论 复制链接分享
  • a510835147 _追逐梦想_ 2016-03-04 00:47

    你的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 小-强 2016-03-04 02:10

    源码: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

    点赞 评论 复制链接分享
  • princess4426 另一只蝴蝶 2016-03-17 07:39

    你给的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
    

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

    点赞 评论 复制链接分享

相关推荐