需求:有一个version_plan表,其中有一个字段is_urgent,且每个version_plan与一个模块moduleId关联,现在要查出is_urgent为1的模块数和这个模块的总数,sql语句如下:
select distinct associated_module_id moduleId,count(*) total,IFNULL(t.total,0) other from version_plan v left join
(SELECT associated_module_id id,count(*) total from version_plan v where is_urgent=1 and FIND_IN_SET(associated_module_id,' 1,2,4,6,7,8,9,10,11,12,13,16,17,18,21,23,24,25,73,30,32,33,34,40,51,52,55,53,54,57,58,59,60,62,63,64,65,66,67,61,42,41,45,46,47,48,49,70,43,44,39,26,71,69,56,72,73') and (v.`expected_release_time` between '2023-04-01'and '2023-04-30')
GROUP BY associated_module_id ) t
on v.associated_module_id=t.id
where FIND_IN_SET(associated_module_id,' 1,2,4,6,7,8,9,10,11,12,13,16,17,18,21,23,24,25,73,30,32,33,34,40,51,52,55,53,54,57,58,59,60,62,63,64,65,66,67,61,42,41,45,46,47,48,49,70,43,44,39,26,71,69,56,72,73') and (v.`expected_release_time` between '2023-04-01'and '2023-04-30')
group by associated_module_id,total order by moduleId
效果:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)