我有 access_log 表
create_time | time_spent --------------+------------ NOV 02, 2017 | 00:00:00 NOV 02, 2017 | 01:45:04 NOV 02, 2017 | 00:00:00 NOV 02, 2017 | 00:00:00 NOV 02, 2017 | 00:39:29 NOV 02, 2017 | 03:05:49 NOV 03, 2017 | 03:58:57 NOV 03, 2017 | 00:52:29 NOV 03, 2017 | 02:53:25
使用此表,使用 PostgreSQL 制作如下所示。它应该添加各自日期的 time_spent 列数据
create_time | time_spent --------------+------------ NOV 02, 2017 | 05:30:22 NOV 03, 2017 | 07:44:51
提前谢谢。
答案 0 :(得分:0)
这是一个简单的小组:
t=# create table access_log (create_time date,time_spent time);
CREATE TABLE
t=# copy access_log from stdin delimiter '|';
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself, or an EOF signal.
>> NOV 02, 2017 | 00:00:00
NOV 02, 2017 | 01:45:04
NOV 02, 2017 | 00:00:00
NOV 02, 2017 | 00:00:00
NOV 02, 2017 | 00:39:29
NOV 02, 2017 | 03:05:49
NOV 03, 2017 | 03:58:57
NOV 03, 2017 | 00:52:29
NOV 03, 2017 | 02:53:25>> >> >> >> >> >> >> >>
>> \.
t=# select sum(time_spent), create_time from access_log group by create_time;
sum | create_time
----------+-------------
05:30:22 | 2017-11-02
07:44:51 | 2017-11-03
(2 rows)