sql >> データベース >  >> RDS >> PostgreSQL

postgresqlで週ごとにグループ化する方法

    複数の年がある場合は、その年も考慮に入れる必要があります。 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;
    


    1. PostgreSQLの非公開スキーマへのrsf::st_writeの使用

    2. 日時をSQLサーバー(日時タイプ)に保存する場合、どの形式で保存しますか?

    3. DBeaverとPostgreSQLのシリアルデータ型の問題

    4. --queryの下の$CONDITIONSの目的は何ですか?