UNION我有这个疑问:集团通过与MariaDB的
select item_code, item_name, First, Second, Third, `Fourth` from (
(SELECT t.item_code, i.item_name, t.actual_qty AS `First`, '' AS `Second`, '' AS `Third`, '' AS `Fourth` FROM tabBin t JOIN `tabItem` i ON i.name = t.item_code WHERE t.warehouse = "Finished Goods")
UNION
(SELECT t.item_code, i.item_name, '' AS `First`, t.actual_qty AS `Second`, '' AS `Third`, '' AS `Fourth` FROM tabBin t JOIN `tabItem` i ON i.name = t.item_code WHERE t.warehouse = "Tank 01 - 1200 KG")
UNION
(SELECT t.item_code, i.item_name, '' AS `First`, '' AS `Second`, t.actual_qty AS `Third`, '' AS `Fourth` FROM tabBin t JOIN `tabItem` i ON i.name = t.item_code WHERE t.warehouse = "Tank 02 - 1200 KG")
UNION
(SELECT t.item_code, i.item_name, '' AS `First`, '' AS `Second`, '' AS `Third`, t.actual_qty AS `Fourth` FROM tabBin t JOIN `tabItem` i ON i.name = t.item_code WHERE t.warehouse = "Tank 03 - 1200 KG")) as temp
GROUP BY temp.item_code, temp.item_name, temp.First, temp.Second, temp.Third, temp.Fourth
这是输出:
item_code item_name first, second, third, fourth
fg-plu PLUM 30.000000
fg-plu PLUM 40.000000
fg-plu PLUM 10.000000
fg-plu PLUM 1248.00
我想组由item_code
和item_name
或只是item_code
。
那么不要使用UNION,而是一个普通的子查询......? – CBroe
会返回很多行。我不知道这是否会继续工作 –
这被称为“pivoting” - 按照我添加的标签。 –