更新时间:2023-01-22 11:45:42
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
要使其与索引一起使用,您可以做
To make it work with indexes you can do
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