以下のクエリに問題があります。受注明細は受注テーブル内の子テーブルです。複数の行を持つテーブル(受注明細)には、最初の項目は最初の行を意味し、他のすべての行は表示されません。光り輝く少年たちを捨ててください。子テーブルの問題 - MySqlクエリ
select
`tabSales Order`.`name` as "Sales Order:Link/Sales Order:120",
`tabSales Order`.`customer` as "Customer:Link/Customer:120",
`tabSales Order Item`.item_code as "Item:Link/Item:120",
`tabSales Order Item`.item_name as "Des:Link/Item:120",
`tabSales Order Item`.qty as "Qty:Int:100",
`tabSales Order Item`.delivered_qty as "Delivered Qty:Int:100",
(`tabSales Order Item`.qty - ifnull(`tabSales Order Item`.delivered_qty, 0)) as "Qty to Deliver:Int:140",
`tabSales Order Item`.date as "Sch date:Date:100",
`tabItem`.thumbnail as "Cut wt:Data:60",
(`tabSales Order Item`.qty * `tabItem`.thumbnail) as "Tonnage:Float:80",
`tabProduct master`.grade as "Grade:Data:100",
`tabProduct master`.dieno as "Die no:Data:100",
`tabProduct master`.hammer as "Hammer:Data:50",
`tabProduct master`.rm_idl_cs as "Idl sec:Data:60",
`tabProduct master`.rm_alt_cs as "Alt sec:Data:60",
ifnull(SUM(CASE WHEN `tabSales Order`.`name` = `tabProduction Order`.`sales_order` and `tabSales Order Item`.`item_code` = `tabProduction Order`.`production_item`
THEN `tabProduction Order`.`qty`
END),0) as "Issued:Int:80",
SUM(CASE WHEN `tabSales Order`.`name` = `tabProduction Order`.`sales_order` and `tabSales Order Item`.`item_code` = `tabProduction Order`.`production_item`
THEN `tabProduction Order`.`produced_qty`
END) as "Cut:Int:80",
(`tabSales Order Item`.qty - ifnull(SUM(CASE WHEN `tabSales Order`.`name` = `tabProduction Order`.`sales_order` and `tabSales Order Item`.`item_code` = `tabProduction Order`.`production_item`
THEN `tabProduction Order`.`qty`
END),0)) as "To be issued:Int:80"
from `tabSales Order`
LEFT JOIN `tabSales Order Item` ON (`tabSales Order Item`.`parent` = `tabSales Order`.`name`
and `tabSales Order`.docstatus = 1 )
LEFT JOIN `tabItem` ON `tabItem`.`item_code` = `tabSales Order Item`.`item_code`
LEFT JOIN `tabProduct master` ON `tabProduct master`.`part_no` = `tabSales Order Item`.`item_code`
LEFT JOIN `tabProduction Order`
ON (`tabSales Order Item`.`item_code` = `tabProduction Order`.`production_item`
and `tabSales Order`.`name` = `tabProduction Order`.`sales_order`)
where `tabSales Order`.status not in ("Stopped", "Closed", "Completed")
and ifnull(`tabSales Order Item`.delivered_qty,0) < ifnull(`tabSales Order Item`.qty, 0)
GROUP BY `tabSales Order`.`name`
HAVING (`tabSales Order Item`.qty -
SUM(CASE WHEN `tabSales Order`.`name` = `tabProduction Order`.`sales_order`
and `tabSales Order Item`.`item_code` = `tabProduction Order`.`production_item`
THEN `tabProduction Order`.`qty` END)
) > 0
or (`tabSales Order Item`.qty -
SUM(CASE WHEN `tabSales Order`.`name` = `tabProduction Order`.`sales_order`
and `tabSales Order Item`.`item_code` = `tabProduction Order`.`production_item`
THEN `tabProduction Order`.`qty` END)
) is NULL;
「HAVING IFNULL(...- SUM(...)、1)」を2度計算する代わりに使用できるかどうかを確認してください。 @RickJames。 –
HAVING IFNULL(..)を使用してみましたが、それでも問題は解決しません。どんな助け?ありがとう – Ragav
申し訳ありませんが、それは単なる簡略化の提案であり、解決策ではありません。 –