CAST(CAST(mrw.total_quantity AS DECIMAL(18,2)) * CAST(mup.attr1 AS DECIMAL(18,5)) AS DECIMAL(18, 6)) AS result,
COUNT(*) OVER (PARTITION BY mur.workorder_code_sap, mur.childprocess_code) AS head_count,
ROUND(
CAST (
CAST(CAST(mrw.total_quantity AS DECIMAL(18,2)) * CAST(mup.attr1 AS DECIMAL(18,5)) AS DECIMAL(18, 6)) / NULLIF ( COUNT ( * ) OVER ( PARTITION BY mur.workorder_code_sap, mur.childprocess_code ), 0 ) AS DECIMAL ( 18, 4 )
),
4
) AS avg_result
FROM
FROM
mes_unitprice_report mur
mes_unitprice_report mur
LEFT JOIN
LEFT JOIN
mes_unit_price mup ON RIGHT(mur.product_code, 11) = mup.product_code AND mur.childprocess_code = mup.childprocess_code
mes_unit_price mup ON RIGHT(mur.product_code, 11) = mup.product_code AND mur.childprocess_code = mup.childprocess_code
LEFT JOIN
LEFT JOIN base_equipment be ON be.equipment_code=mur.line_code
(SELECT
LEFT JOIN ( SELECT parent_order, SUM ( quantity ) AS total_quantity FROM mes_report_work GROUP BY parent_order ) mrw ON mur.workorder_code = mrw.parent_order
workorder_code,
SUM(quantity) AS total_quantity
FROM
mes_report_work
<where>
<where>
<iftest="workorderCode != null and workorderCode != ''">and workorder_code = #{workorderCode}</if>
<iftest="workorderCode != null and workorderCode != ''">and workorder_code = #{workorderCode}</if>
<iftest="workorderCodeSap != null and workorderCodeSap != ''">and workorder_code_sap =
<iftest="workorderCodeSap != null and workorderCodeSap != ''">and mur.workorder_code_sap =
#{workorderCodeSap}
#{workorderCodeSap}
</if>
</if>
<iftest="productName != null and productName != ''">and product_name like concat('%', #{productName},
<iftest="productName != null and productName != ''">and mur.product_name like concat('%', #{productName},
'%')
'%')
</if>
</if>
<iftest="productCode != null and productCode != ''">and product_code = #{productCode}</if>
<iftest="productCode != null and productCode != ''">and mur.product_code = #{productCode}</if>
<iftest="userName != null and userName != ''">and user_name like concat('%', #{userName}, '%')</if>
<iftest="userName != null and userName != ''">and user_name like concat('%', #{userName}, '%')</if>
<iftest="nickName != null and nickName != ''">and nick_name like concat('%', #{nickName}, '%')</if>
<iftest="nickName != null and nickName != ''">and nick_name like concat('%', #{nickName}, '%')</if>
<iftest="childprocessCode != null and childprocessCode != ''">and childprocess_code =
<iftest="childprocessCode != null and childprocessCode != ''">and childprocess_code =
@ -74,12 +86,14 @@
<iftest="attr3 != null and attr3 != ''">and attr3 = #{attr3}</if>
<iftest="attr3 != null and attr3 != ''">and attr3 = #{attr3}</if>
</where>
</where>
GROUP BY
GROUP BY
workorder_code) mrw ON mur.workorder_code = mrw.workorder_code