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週目は過去7日間です。過去の週までのPostgresql件数
理想的には、週ごとにグループ化された過去8週間の各チームのローン数を示す表が理想的です。
これを行うための最善の方法上の任意のアイデアを:出力は次のようになりますか?
Mysqlまたはpostgresql? – GurV
@GurV私にPostgresのように見える –