4
我想從過去12個月的數據庫表中提取記錄。這是我到目前爲止所嘗試的。按月分組,如果沒有找到記錄,則返回0
SELECT COUNT(s.id), date_part('month', s.viewed_at) month_number
FROM statistics_maps_view as s
INNER JOIN maps as m
ON s.maps_id=m.id Where m.users_id = $users_id group by month_number ORDER BY month_number DESC LIMIT 12
我知道這會記錄明智的月份。但是如果某個月沒有記錄,是否可以添加Count = 0
?