select
Average,
Homogen,
difference,
net_weight,
jsonb_array_elements(testData::jsonb) ->> 'MaxPower' AS maxpower,
jsonb_array_elements(testData::jsonb) ->> 'Thickness' AS thickness,
jsonb_array_elements(testData::jsonb) ->> 'Refraction' AS refraction,
FurnaceID,
equipmentNo as FurnaceID,
lineNo as FurnaceID,
creationDate,
case
when to_char(creationDate, 'HH24MI')::INTEGER >= 800 and to_char(creationDate, 'HH24MI')::INTEGER < 2000 then to_char(creationDate 'MM/DD') || 'D'
when to_char(creationDate, 'HH24MI')::INTEGER >= 2000 then to_char(creationDate 'MM/DD') || 'N'
else to_char(creationDate - INTERVAL '1 day', 'MM/DD') || 'N'
end AS timeStr
from
battery_spc_gather_auto
spc_anneal_offline
spc_anneal_offline
spc_oxidation_offline
battert_spc_scales_texturing
battert_spc_scales_alkalicase
spc_texturing_offline
spc_alkalicase_offline
spc_pepoly_offline
spc_alumina1_offline
spc_alumina2_offline
spc_positive_membrane_offline
spc_dorsal_membrane_offline
spc_pullingforce1_offline
spc_pullingforce2_offline
spc_threepointbendingresistance_offline
battert_spc_scales_silk
where 1=1
and bsga.workshop = 'C1'
and ${reportCombox} = 1
and Average != '0.0'
and difference IS NOT NULL
and net_weight IS NOT NULL
and testData IS NOT NULL
and creationDate >= to_timestamp('${startDate}', 'YYYY-MM-DD HH24:MI:SS')
and creationDate < to_timestamp('${endDate}', 'YYYY-MM-DD HH24:MI:SS')
${if(len(deviceId)>0, " and FurnaceID in ('" +deviceId+ "') ","")}
${if(len(deviceId)>0, " and equipmentNo in ('" +deviceId+ "') ","")}
${if(len(deviceId)>0, " and lineNo in ('" +deviceId+ "') ","")}
order by timeStr