flappyfish 2017-11-14 02:45 采纳率: 100%
浏览 3433
已采纳

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条)

报告相同问题?

悬赏问题

  • ¥15 wamp3.3.5安装完成后图标正常显示绿色,鼠标左右键点击图标均无反应。求解决方法。
  • ¥15 鼠标点击的这条记录了什么?
  • ¥15 在写pid调速的程序时,电机始终维持最大速度
  • ¥15 帅锅们,我很想知道这个论坛是用什么模板搭的(T_T)
  • ¥15 请问如何查看手机root记录?
  • ¥15 商城小程序订单号重复
  • ¥15 学校优化算法sbo和蚁群算法怎么结合
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素