所以我必须根据日期和产品到达的时间对表格进行分组,时间将是:
morning = [5, 6, 7 , 8, 9]
mid_morning = [10, 11]
midday = [12, 13, 14]
evening = [15, 16, 17 ,18 ,19, 20]
night = [21, 22, 23, 0, 1, 2, 3, 4]
这是表格:
CREATE TABLE inventory (
inventory_id serial PRIMARY KEY,
arrive_date date NOT NULL,
arrive_location character varying NOT NULL,
thing_type integer NOT NULL,
quantity integer NOT NULL
);
INSERT INTO inventory (arrive_date, arrive_location, thing_type, quantity) VALUES
('2018-05-30 05:00:00-00', 'location_00', 3, 2)
, ('2018-05-30 06:00:00-00', 'location_00', 3, 8)
, ('2018-05-30 12:50:00-00', 'location_00', 5, 2)
, ('2018-05-30 13:40:00-00', 'location_00', 1, 3)
, ('2018-05-31 13:00:00-00', 'location_00', 4, 7)
, ('2018-05-31 18:00:00-00', 'location_00', 2, 3)
;
期望的结果是得到这个表结果:
preprocess_id | 到达日期 | 到达时间天 | 到达位置 | 数据 |
---|---|---|---|---|
33 | 2018-05-30 | 0 | 位置_00 | {“3”:10} |
34 | 2018-05-30 | 2 | 位置_00 | { "5": 2, "1": 3 } |
36 | 2018-05-31 | 2 | 位置_00 | {“4”:7} |
37 | 2018-05-31 | 4 | 位置_00 | {“2”:3} |
我只有按天分组的当前查询小提琴,是否可以有日期然后是白天?