公司同事写的sql

项目表(tb_project)、项目下用户表(tb_project_user)、项目交接表(tb_project_handover)

条件分页查询用户下项目交接列表

在这里插入图片描述

<select id="projectList" resultType="com.hnwel.modules.crc.dto.ProjectProjectHandoverDto"
            parameterType="com.hnwel.modules.crc.query.ProjectQuery">
        SELECT p.dept_id,
               p.dept_name,
               p.pi_name,
               p.id,
               p.project_name,
               p.trial_scheme_no,
               p.project_type,
               p.sponsor,
               p.smo_id,
               p.smo_name,
               p.start_time,
               h.handover_type,
               (select count(*) from tb_project_crc where project_id = p.id and status = 1) as numberPeople
        from tb_project_handover h
                 left join
             (
                 select *
                 from tb_project
                 where id in
                       (
                           select pu.project_id
                           from tb_project_user pu
                                    left join tb_project p on pu.id = p.id
                            <where>
                                pu.user_id = #{userId}
                                <if test="trialSchemeNo != null and trialSchemeNo != ''"> and pu.trial_scheme_no like concat(#{trialSchemeNo}, '%')</if>
                                <if test="deptName != null  and deptName != ''"> and pu.dept_name like concat(#{deptName}, '%')</if>
                                <if test="smoName != null  and smoName != ''"> and pu.smo_name like concat(#{smoName}, '%')</if>
                                <if test="startTime != null "> and pu.start_time = #{startTime}</if>
                            </where>
                       )
             ) p on h.project_id = p.id
        <where>
            <if test="handoverType != null and handoverType != ''"> and h.handover_type = #{handoverType}</if>
        </where>
        limit #{startRow},#{pageNumber}
    </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值