postgresqldatepostgresql-8.2

PostgreSQL 8.2 extract week number from a a date field


This might be a simple one but I haven't got a solution yet. I have a create_date field which is a date type, and a revenue number. I want to see weekly break down of revenue.

I can get the numbers easily in tableau because of built in functionality but doing it in PostgreSQL is where I need some help.


Solution

  • If you want the revenue by week, you'll need to group and aggregate:

    select extract (week from create_date) as week, sum(revenue) from table group by week