複数の年がある場合は、その年も考慮に入れる必要があります。 1つの方法は次のとおりです:
SELECT date_part('year', author_date::date) as year,
date_part('week', author_date::date) AS weekly,
COUNT(author_email)
FROM commits
GROUP BY year, weekly
ORDER BY year, weekly;
これを書くより自然な方法は、date_trunc()
を使用します :
SELECT date_trunc('week', author_date::date) AS weekly,
COUNT(author_email)
FROM commits
GROUP BY weekly
ORDER BY weekly;