flappyfish
2017-11-14 02:45
采纳率: 100%
浏览 3.4k

mybatis执行select子查询分页报错

select
    adr.modifiedname,
    adr.modifiedon,
    adr.comment_tag,
    adr.post_desc,
    adr.qualifications,
    (
    SELECT
                GROUP_CONCAT(r.user_name)
                FROM
                post_recruiter_related r
                WHERE
                r.post_id =  ah.post_id
                AND r.isdeleted = 0
    ) AS recruitPersons
    from ad_headhunter_related ah LEFT JOIN ad_release_record adr ON ah.post_id = adr.post_id
    where adr.isdeleted=0
   HAVING recruitPersons like '%杰%'
    ORDER by ah.create_time DESC

我有一条sql语句,其中select里面有一个子句关联另一张表,这条sql单独执行没问题,但是配合PageHelper分页就报错,提示“ SELECT count(0) FROM ad_headhunter_related ah LEFT JOIN ad_release_record adr ON ah.post_id = adr.post_id WHERE adr.isdeleted = 0 AND ah.is_deleted = 0 AND ah.hunter_id = 83 AND adr.post_nameE '%杰%' HAVING recruitPerons LIKE CONCAT('
%', ?, '%')
提示找不到recruitPersons这个列,这是什么原因呢?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

6条回答 默认 最新

  • sheng94458 2017-11-14 03:41
    最佳回答

    SELECT count(0) FROM ad_headhunter_related ah LEFT JOIN ad_release_record adr ON ah.post_id = adr.post_id WHERE adr.isdeleted = 0 AND ah.is_deleted = 0 AND ah.hunter_id = 83 AND adr.post_nameE '%杰%' HAVING recruitPerons LIKE CONCAT('
    %', ?, '%')

    这个sql肯定是会提示找不到recruitPersons这个列,这句sql应该是分页时查询数据总数的吧?你可以试试这样改改,因为你查询数据总数时,并没有把recruitPersons这列查询出来,这个是子查询出来的临时字段并不是数据库字段

         select count(*) from (SELECT  (SELECT GROUP_CONCAT(r.user_name) FROM post_recruiter_related r WHERE r.post_id =  ah.post_id AND r.isdeleted = 0) AS recruitPersons FROM ad_headhunter_related ah LEFT JOIN ad_release_record adr ON ah.post_id = adr.post_id WHERE adr.isdeleted = 0 
    

    AND ah.is_deleted = 0 AND ah.hunter_id = 83 AND adr.post_nameE '%杰%' HAVING recruitPerons LIKE CONCAT('%', ?, '%')) as tab1

    评论
    解决 无用
    打赏 举报
查看更多回答(5条)

相关推荐 更多相似问题