当前位置:   article > 正文

mysql 一个字段多个id逗号分隔关联查询_多个id放在一个字段查询走索引

多个id放在一个字段查询走索引

mysql 一个字段多个id逗号分隔关联查询

关键点是:FIND_IN_SET、GROUP_CONCAT、GROUP BY

  1. -- mysql 查询逗号分隔的多个id
  2. select t1.id,t1.chapter_id,
  3. t2.id,t2.name as bookVersionName,
  4. GROUP_CONCAT(t3.`name`) as chapterName,
  5. t4.id,t4.name as volumeName
  6. from co_course_pj as t1,
  7. co_book_version as t2,
  8. co_chapter as t3,
  9. co_volume as t4
  10. where t1.`status` != "0"
  11. and t2.id = t1.book_version_id
  12. and FIND_IN_SET(t3.id, t1.chapter_id)
  13. and t4.id = t1.volume_id
  14. GROUP BY t1.id;
  15. -- 科目学段
  16. SELECT
  17. t1.id, t1.`name`, t1.stage_ids, GROUP_CONCAT(t2.`name`) AS stageNames
  18. FROM co_subject as t1
  19. left JOIN co_school_stage as t2 ON FIND_IN_SET(t2.id,t1.stage_ids) and t2.`status` != "0"
  20. GROUP BY t1.id;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/230836
推荐阅读
相关标签
  

闽ICP备14008679号