select a.code,a.setdepot_id,d.depotid,c1.clothingid,c.styleid,b.nums,COUNT(TMID) smNUMS into #THFH from u_outindentset a left join u_outindentsetsub b on a.id=b.code left join u_outindentsetstyle f on b.style_code = f.id left join b_style c on f.style_id=c.id left join B_Clothing c1 on b.clothing_id=c1.id left join b_depot d on a.depot_id=d.id left join F100_Label.dbo.tm_formlist e on b.clothing_id=e.clothing_id and a.id=e.code --left join t18_tmlist e on b.clothingid=e.clothingid and a.outindentid=e.tmlistid where a.setdepot_id in ('${id}') --a.setdepot_id = '6655674755462550467' --d.depotid = '25371013'and and a.sure='1' and a.states = '2' and a.sure_date>='${begin}' --and a.sure_date>='2020-01-01' and a.sure_date-1<'${end}' --and a.sure_date-1<'2020-12-01' --and d.depotid='11203' group by a.code,a.setdepot_id,d.depotid,c1.clothingid,c.styleid,b.nums
select a.code,a.depotid,b.s_name,a.clothingid,a.styleid,nums,smNUMS from #THFH a left join dbo.b_depot b on a.setdepot_id=b.id where nums>smNUMS |