我希望查询3个表(客户,销售和顶级商品),并创建每个客户尚未购买的顶级商品列表。
相关字段
客户:客户#
销售:发票#,客户#,项目#
热门项目:项目#
答案 0 :(得分:-1)
SELECT c.*, GROUP_CONCAT(t.`Item#`) AS list_of_top_items_not_purchased
FROM Customers c
CROSS JOIN `Top-Items` t
LEFT OUTER JOIN Sales s ON c.`Customer#` = s.`Customer#` AND s.`Item#` = t.`Item#`
WHERE s.`Item#` IS NULL
GROUP BY c.`Customer#`;