我有三个表 tl_log、tl_geo_countries、tl_ purpose。我正在尝试获取表“tl_log”中每个国家/地区花费的天数,用于表“tl_ purpose”中的每个目的。我试过下面的mysql查询
SELECT t.country_id AS countryID,t.reason_id AS reasonID,count(t.reason_id) AS
days,c.name AS country, p.purpose AS purpose
FROM `tl_log` AS t
LEFT JOIN tl_geo_countries AS c ON t.country_id=c.id
LEFT JOIN tl_purpose AS p ON t.reason_id=p.id
GROUP BY t.reason_id,t.country_id ORDER BY days DESC
但着陆了。
我无法获得表“tl_log”中不存在的“tl_log”中每个国家/地区的目的计数。任何帮助是极大的赞赏。另外,如果问题难以理解,请告诉我。
预期输出:
下面是这三个表的结构
tl_log
tl_geo_countries
tl_目的