我想输出一个客户列表,其中包含他注册的名称和事件计数。
像这样:
max (3)Sports,Food,Cinema
tom (2) Food, Sports
我无法让它工作。我总是得到这个结果:
max Sports
max Food
max Cinema
tom Food
tom Sports
我大约有这个表设置:
+-----+-----------+-------+-----+
+ CID + Customer + misc..+ ... +
+-----+-----------+-------+-----+
+ 1 + max + abc + ... +
+-----+-----------+-------+-----+
+ 2 + tom + xyz + ... +
+-----+-----------+-------+-----+
+-----+------------+--------+---------+-----+
+ EID + RID + Event + misc... + ... +
+-----+------------+--------+---------+-----+
+ 1 + + Sports + misc... + ... +
+-----+------------+--------+---------+-----+
+ 2 + + food + misc... + ... +
+-----+------------+--------+---------+-----+
+ 3 + + cinema + misc... + ... +
+-----+------------+--------+---------+-----+
+ 4 + + Event + misc... + ... +
+-----+------------+--------+---------+-----+
+-----+-----+-----+
+ RID + EID + CID +
+-----+-----+-----+
+ 1 + 1 + 1 +
+-----+-----+-----+
+ 2 + 2 + 1 +
+-----+-----+-----+
+ 3 + 3 + 1 +
+-----+-----+-----+
+ 4 + 1 + 2 +
+-----+-----+-----+
+ 5 + 2 + 2 +
+-----+-----+-----+
我已经用 GROUP_CONCAT() 试过了,但这似乎不是它的工作方式......
我已加入所有表,但我认为我需要 2 个查询来解决此任务。
我在我的while循环中尝试了一个选择,但这太慢了……
我试过这个:
$sql1 = "SELECT et.Art, et.Kategorie, et.ID, et.Event AS Event1,
GROUP_CONCAT( loc.ORT ) AS ORT1
FROM ".DB_CUSTOMERS_TABLE." AS et
JOIN ".DB_RELATIONS_TABLE." AS rel
ON (et.id = rel.EID)
JOIN ".DB_EVENT_TABLE." AS loc
ON (loc.Location_ID = rel.Location_ID)
GROUP BY rel.EID
";
我需要一个想法,我怎样才能以一种好的方式解决这个问题。
谢谢阅读。我希望我不要混淆。