youyaoqimingzhi 2021-06-03 19:18 采纳率: 66.7%
浏览 53
已采纳

子查询返回值不止一个如何处理

根据商铺shopId查询用户tb_users得到多个用户的u_id来查询其它结果
<select id="selectStudentsStatisticalVoList" parameterType="integer" >/*parameterType="com.ruoyi.goods.entity.vo.StudentsStatisticalVo"*/
    select tus.user_name,
           tus.user_avatar,
           td.name,
            (select count(*) from tb_study_goods where tus.shop_id = sg.shop_id and tus.u_id = sg.u_id) as studyFor,
            /*count(case when is_complete = 1 then 1 else null end ) as finishNum,*/
            (select count(*) from tb_study_goods where tus.shop_id = sg.shop_id and tus.u_id = sg.u_id and sg.is_complete = 1) as finishNum,
            (select sum (study_length) from tb_study_goods where tus.shop_id = sg.shop_id and tus.u_id = sg.u_id) as studyLength,
            (select count (*) from tb_chapter_goods_rela where tcgr.shop_id = tus.shop_id and tcgr.train_id = #{trainId}) as course,
            (select create_time from tb_study_goods where tus.shop_id = sg.shop_id and tus.u_id = sg.u_id order by create_time) as createTime

           from tb_users tus
           left join tb_study_goods sg on tus.shop_id = sg.shop_id and tus.u_id = sg.u_id
           left join tb_chapter_goods_rela tcgr on tcgr.shop_id = tus.shop_id and tcgr.train_id = #{trainId}
           left join tb_department td on td.department_id = tus.depart_id
           where
           tus.shop_id = #{shopId}

</select>
  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-06-03 19:23
    关注

    加limit 1吧,就只返回一条了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?