 select 
       se.f_sgrp se_sgrp, 
       se.f_sgtm se_sgtm, 
       se.f_tsno se_tsno, 
       se.f_val se_val, 
       rd.f_name rd_name, 
       jd.f_name jd_name, 
       pl.f_name pl_name, 
       pd.f_name pd_name, 
       td.f_test td_test, 
       td.f_name td_name, 
       (select count(ev.f_evnt) 
       from [spcepiworld].[dbo].[evnt_inf] ev 
       where ev.f_prcs = rd.f_prcs 
         and ev.f_part = pd.f_part 
         and ev.f_sgtm = se.f_sgtm) ev_count 
 from [spcepiworld].[dbo].[sgrp_ext] se 
 join [spcepiworld].[dbo].[prcs_dat] rd 
   on se.f_prcs = rd.f_prcs 
 join [spcepiworld].[dbo].[job_dat] jd 
   on se.f_job = jd.f_job 
 join [spcepiworld].[dbo].[part_lot] pl 
   on se.f_lot = pl.f_lot 
 join [spcepiworld].[dbo].[part_dat] pd 
   on se.f_part = pd.f_part 
 join [spcepiworld].[dbo].[test_dat] td  
   on se.f_test = td.f_test 
 where se.f_flag = 0 
   and se.f_sgrp = 1677273357  
   and rd.f_name = '61' 
   and pd.f_name = '5012' 
   and jd.f_name = 'CDE5' 
   and pl.f_name = '575908' 
   and dateadd(HH, -7, (dateadd(SS, convert(bigint, se.f_sgtm), '19700101'))) = '2023-02-24 15:15:00' 
   for json path 
