我的申请是用于比较每个商家每天销售的产品。进程运行以加载每个商店的当前数据值,并将其与任何先前数据一起输入数据库。后来我计划创建图表等数据历史。
SELECT `a`.`part_number`, GROUP_CONCAT(`a`.`seller_id` ORDER BY `price` ASC), GROUP_CONCAT(`b`.`part_id` ORDER BY `price` ASC), GROUP_CONCAT(`b`.`price` ORDER BY `price` ASC)
FROM `parts`
LEFT JOIN (
SELECT *
FROM (
SELECT *
FROM `parts_data` AS `tmp_a`
ORDER BY `date_added` DESC
) AS `tmp_b`
GROUP BY `part_id`
) AS `b`
ON `a`.`part_id` = `b`.`part_id`
GROUP BY `a`.`part_number`
为了解释一下这个问题,我需要为几个部件ID 选择最新的价格信息,并将它们与选定的部件号组合在一起进行比较。此外,在连接时,分组的项目按价格排序为从最高到最低。
每个零件编号也可以包含任意数量的项目ID,因此不会影响正在监视的公司数量。
part_number | column1 | column2 | column3
++++++++++++++++++++++++++++++++++++++++++++++++
| seller:A1 | seller:A3 | seller:A6
153231 | id:x423 | id:x534 | id:x902
| cost:23 | cost:34 | cost:57
++++++++++++++++++++++++++++++++++++++++++++++++
| seller:A3 | seller:A1 | seller:A6
345123 | id:x313 | id:x631 | id:x652
| cost:78 | cost:86 | cost:99
++++++++++++++++++++++++++++++++++++++++++++++++
| seller:A5 | seller:A1 |
231756 | id:x663 | id:x291 |
| cost:35 | cost:52 |