您好我已尝试制作视图,但我遇到了这个问题,我已经研究过并发现我需要先将观点分开,但我发现它真的很难,我很乐意需要一些帮助。
由于
SELECT
coalesce((`rawmat_pallet_ag`.`sheets_pallet` * `rawmat_pallet_ag`.`outs_pallet`),0) AS agpcs,
coalesce(((`rawmat_pallet`.`no_pallet` * `rawmat_pallet`.`sheets_pallet`) * `rawmat_pallet`.`out_pallet`),0) AS printedpcs,
coalesce(`rawmat_pcs`.`quantity`,0) AS rawpcs,
((coalesce((`rawmat_pallet_ag`.`sheets_pallet` * `rawmat_pallet_ag`.`outs_pallet`),0) + coalesce(((`rawmat_pallet`.`no_pallet` * `rawmat_pallet`.`sheets_pallet`) * `rawmat_pallet`.`out_pallet`),0)) + coalesce(`rawmat_pcs`.`quantity`,0)) AS total,
rawmaterial.rawmaterial_code AS rawmaterial_code,
rawmaterial.rawmaterial_desc AS rawmaterial_desc,
rawmaterial.rawmaterial_id AS raw_id,
second_view.pending_total,
COALESCE(total - second_view.pending_total) as available_qty
FROM
rawmat_pallet_ag
RIGHT JOIN rawmaterial
ON rawmat_pallet_ag.raw_id = rawmaterial.rawmaterial_id
LEFT JOIN rawmat_pallet
ON rawmat_pallet.raw_id = rawmaterial.rawmaterial_id
LEFT JOIN rawmat_pcs
ON rawmat_pcs.raw_id = rawmaterial.rawmaterial_id
LEFT JOIN (select rawid,sum(first_view.total) as pending_total FROM
assignedraw LEFT JOIN
(SELECT
jo_main.item_id,
sum(jo_main.qty) as total
FROM
jo_main
JOIN so_jo
ON jo_main.jomain_id = so_jo.jomain_id
JOIN somain
ON so_jo.somain_id = somain.salesorder_id
where somain.`status` = 1
group by jo_main.item_id) AS first_view
ON assignedraw.itemid = first_view.item_id
group by assignedraw.rawid) as second_view
ON rawmaterial.rawmaterial_id = second_view.rawid
GROUP BY
`rawmaterial`.`rawmaterial_id`
ORDER BY
raw_id ASC