如何获取引用者的所有线索和命中?来自不同不同表格的sql多个计数
表:hits_log
+-----------+----------+
| topic | referer |
+-----------+----------+
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
| topic0614 | yyyyyy |
| topic0614 | yyyyyy |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
+-----------+----------+
表:leads_log
+-----------+----------+
| topic | referer |
+-----------+----------+
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0615 | yyyyyy |
| topic0614 | xxxxxxxx |
| topic0615 | zzzzz |
| topic0614 | yyyyyy |
+-----------+----------+
我想这样 结果如果与主题搜索topic0614
+-----------+----------+------------+
| referer | hits | leads |
+-----------+----------+------------+
| xxxxxxxx | 4 | 4 |
| yyyyyy | 2 | 1 |
+-----------+----------+------------+
我曾尝试
SELECT h.referer, COUNT(h.referer) as hits, COUNT(l.referer) as leads FROM `hits_log` h ,`leads_log` l
WHERE h.topic='topic0614' and h.referer=l.referer
GROUP BY h.referer
,但它没有工作
任何一个能帮助我吗?谢谢。
为什么'xxxxxxxx'在你的样品输出引线5?我只在'leads_log'表中看到4。为什么'yyyyyy'只有1,'leads_log'表中有2个。 – Barmar
我没有来自hit_log的hit,也没有来自lead logs独立存储的线索,所以它就是这样的 – Lucifer
但'xxxxxxxx'只有4行'hits_log',为什么在结果中有'5'? – Barmar