How to get number of invoices for last 12 weeks in Postgres
问题 Invoice database contains invoice dates: create table dok ( dokumnr serial primary key, invoicedate date not null ); Dashboard requires comma separated list containing number of invoices for last 12 weeks, e.q 4,8,0,6,7,6,0,6,0,4,5,6 List contains always 12 elements. If there are no invoices for some 7 day interval, 0 should appear. Every element should contain number of invoices for 7 days. Query should find maximum date before current date: select max(invoicedate) as last_date from dok; And