这是我当前的SQL查询
SELECT
urls.short,
urls.long,
urls.user,
dates.date AS date,
COUNT(views.short) AS views,
SUM(views.money) AS money
FROM dates
LEFT JOIN views ON dates.date = views.date
LEFT JOIN urls ON views.short = urls.short
WHERE urls.user='test'
GROUP BY dates.date, views.date
LIMIT 0, 20
它显示的结果如下:
2011-02-08 test test 1 0.003
2011-02-09 test test 6 0.016
但是当我删除
WHERE urls.user='test'
我得到了
2011-02-05 0
2011-02-06 0
2011-02-07 44kc http://google.com 27 0.031
2011-02-08 44kc http://google.com 15 0.045
2011-02-09 test test 12 0.032
2011-02-10 0
所以最后我想使用第一个查询得到第二个查询结果(显示0,当没有可用的时候)。 那么解决方案是什么?
答案 0 :(得分:10)
我不确定我是否正确理解了您的问题,但您可能需要考虑
LEFT JOIN urls ON views.short = urls.short AND urls.user='test'