row_number() over (order by cast(eo.actual_operation_time as decimal(6, 2))/2 desc) as serialNumber,
eo.equipment_code as equipmentCode,
cast(cast(eo.actual_operation_time as decimal(18,2))/(SELECT count(*) from equ_repair_work_order erwo where erwo.equipment_code = eo.equipment_code and erwo.work_status = '1' and erwo.work_down_machine = '1') as decimal(18,2)) AS mtbf
row_number() over (ORDER BY sum(CASE WHEN eor.type = 'on' THEN cast(datediff(minute, eor.start_time,eor.end_time)*1.0/60 as decimal(10,2)) ELSE null END )/sum(CASE WHEN type = 'off' THEN 1 ELSE 0 END) DESC) AS serialNumber,
eor.equipment_code AS equipmentCode,
sum(CASE WHEN eor.type = 'on' THEN cast(datediff(minute, eor.start_time,eor.end_time)*1.0/60 as decimal(10,2)) ELSE null END ) AS onTime,
sum(CASE WHEN eor.type = 'off' THEN 1 ELSE 0 END) AS shutDownNumber,
cast(sum(CASE WHEN eor.type = 'on' THEN datediff(minute, eor.start_time,eor.end_time)*1.0/60 ELSE null END )/sum(CASE WHEN type = 'off' THEN 1 ELSE 0 END)as decimal(10,2)) as mtbf
from equ_operation_record eor
left join base_equipment be on eor.equipment_code = be.equipment_code