SELECT users.username, users.id, count(tahminler.tahmin)as tahmins_no FROM users LEFT JOIN tahminler ON users.id = tahminler.user_id where year(timestamp) = 2013 and month(timestamp) = 9 GROUP BY users.id having count(tahminler.tahmin) > 0
For at få det til at fungere med indekser kan du gøre
SELECT users.username, users.id, count(tahminler.tahmin)as tahmins_no
FROM users
LEFT JOIN tahminler ON users.id = tahminler.user_id
where timestamp >= '2013-09-01' and timestamp < '2013-10-01'
GROUP BY users.id
having count(tahminler.tahmin) > 0