我有下表
CREATE TABLE public.listing
(
id bigint NOT NULL DEFAULT nextval('listing_id_seq'::regclass),
listing_url text NOT NULL,
insert_time timestamp with time zone DEFAULT now(),
CONSTRAINT listing_pkey PRIMARY KEY (id),
CONSTRAINT listing_listing_url UNIQUE (listing_url)
)
如何获取过去一周每天插入的平均行数?
答案 0 :(得分:1)
我认为您可以采取过去一周出现的记录数量,并将一周中的天数除以7:
select count(*) / 7
from public.listing
where insert_time > current_date - interval '7 days' -- inserts happening in past week
答案 1 :(得分:0)
从列表中选择COUNT(*)/ 7,其中insert_time介于' 2016-09-01'和' 2016-09-07' group by insert_time