String sql = " select *from choice a where a.choiceId not in (select (choiceId) from paperchoice b where b.paperId = "
+ paperId + ")";
3Q啦!!!求学习~~~

解决方案 »

  1.   

    不懂 你要什么... 你这不是sql?  是不好使? 还是别的意思?
      

  2.   

       这个是sql  要换成HQL的语句!!
      

  3.   

    直接
    hql="from choice a where a.choiceId not in (select choiceId from paperchoice b where b.paperId =?"
    这样不行?
      

  4.   


    比如choice 对应的是Choice 实体类
    paperchoice  对应Paperchoice  实体类的话
    且都有choiceId字段  属性的话
    String hql = " select c from Choice as c where c.choiceId not exists  (select  p.choiceId from Paperchoice as p where p.paperId = " + paperId + ")  " ;用exists 性能比 in 要好点、少数据下in 快些、 数据量多就是exists会快点、
      

  5.   

    String sql = " SELECT * FROM  choice A LEFT JOIN paperchoice B ON  B.choiceId IS NULL WHERE A.choiceId=B.choiceId AND B.paperId = "
    + paperId + ")";
      

  6.   

    SELECT * FROM PAPERCHOICE A LEFT JOIN CHOICE B ON A.CHOICEID = B.CHOICEID WHERE A.PAPERID = ?