select id, wk0_count
from teams
left join
(select team_id, count(team_id) as wk0_count
from (
select created_at, team_id, trunc(EXTRACT(EPOCH FROM age(CURRENT_TIMESTAMP,created_at))/604800) as wk_offset
from loan_files
where loan_type <> 2
order by created_at DESC) as t1
where wk_offset = 0
group by team_id) as t_wk0
on teams.id = t_wk0.team_id
我已經創建了上面的查詢,顯示了每個團隊在給定的一週內做了多少貸款。第0周是過去七天。Postgresql過去數星期
理想情況下,我需要一張表格,顯示每個團隊在過去8周內按每週分組的數量。輸出將如下所示:
任何想法上做到這一點的最好方法是什麼?
Mysql或postgresql? – GurV
@GurV看起來像Postgres給我 –