我已经显示了截至特定日期的可用组件数量和库存历史成本的数据。使用以下查询可以正常工作。
SELECT s.part_id,
sum(s.updated_quantity),
p.item_code,
sum(
(SELECT (s.updated_quantity * cost)
FROM inventory
WHERE inventory.id=s.inv_id)) AS tcost
FROM status_history AS s,
inventory AS i,
part_master AS p
WHERE s.action='add'
AND DATE(s.date_created)<='2013-04-09'
AND i.currency_id=1
AND s.inv_id=i.id
AND s.part_id=p.id
GROUP BY s.part_id
我还想在单个字段中显示用逗号分隔的组件的位置名称。为了得到我想要的结果,我尝试了下面的查询,但它只返回一个位置名称,而不是多个位置名称的逗号分隔字符串。
SELECT s.part_id,
sum(s.updated_quantity),
p.item_code,
sum(
(SELECT (s.updated_quantity * cost)
FROM inventory
WHERE inventory.id=s.inv_id)) AS tcost,
CONCAT_WS(',',
(SELECT name
FROM location_master
WHERE id=i.location_id)) AS LOCATION
FROM status_history AS s,
inventory AS i,
part_master AS p
WHERE s.action='add'
AND DATE(s.date_created)<='2013-04-09'
AND i.currency_id=1
AND s.inv_id=i.id
AND s.part_id=p.id
GROUP BY s.part_id