对于统计数据,我想展示每个国家/地区的“最佳生产商”。有两个表:dog 和 owner。在主人有国家在狗是所有其他nessecary。我计算 dog.id 是父亲身份的频率。
对于我指定的一个国家
$result = mysql_query("
SELECT
dog.father_id, dog1.id, dog1.dogname, dog1.owner_id, dog.date_of_birth,
COUNT(dog.father_id) anzahl,
owner.country_short
FROM
dog
LEFT JOIN dog as dog1 ON
(dog.father_id = dog1.id)
LEFT JOIN owner ON
(dog1.owner_id = owner.id)
WHERE dog.father_id !=0
AND dog1.date_of_birth >= DATE_SUB(CURDATE(), INTERVAL 10 YEAR)
AND owner.country_short ='de'
AND owner.kennel_note =''
GROUP BY
dog.father_id
ORDER BY
anzahl DESC
LIMIT 3
", $db) OR die(mysql_error());
while($row = mysql_fetch_array($result))
{ ....
我该如何为每个国家做(从数据库中自动获取)?使用 SET @ 的解决方案会给我一个解析错误。非常感谢您的帮助。