在 SQL 操作方面,我并不太先进。我有来自横幅系统的以下 4 个表格来宣传我的博客:
banners
-id
-other irrelevant data
clicks
-id
-bid (banner id)
-other irrelevant data
exits (people who clicked on the banner and never used the blog or registered an account)
-id
-bid
postregistered (used the banner and register to the blog)
-id
-bid
现在我想生成一个简单的报告来向我展示每个横幅的total number of clicks
,exits
和reg's
。
我试过这个:
SELECT COUNT(c.id) as clicks, COUNT(e.id) as exits, COUNT(r.id) as reg
FROM banners b
LEFT JOIN clicks c
ON c.bid = b.id
LEFT JOIN exits e
ON e.bid = b.id
LEFT JOIN registered r
ON r.bid = b.id
GROUP BY b.name
但它只是让 mysql 杀死我的处理器并且永远不会完成,没有足够的数据让它成为一个繁重的查询。
请你能帮助我,对不起,如果这看起来很基本。
编辑:
我可以运行每个 Left join 自己的并获得正确的结果,但我宁愿将其作为单个查询运行