创建表插入数据:
create table test
(patient int,
visit_id int,
recording_date date,
value1 number(6,2),
value2 int,
value3 int);
insert into test values (1562074,1,to_date('2017-12-27','yyyy-mm-dd'),null,0,null);
insert into test values (1562074,1,to_date('2017-12-25','yyyy-mm-dd'),null,null,60);
insert into test values (1562074,1,to_date('2017-12-13','yyyy-mm-dd'),null,null,67);
insert into test values (1562074,1,to_date('2017-12-25','yyyy-mm-dd'),38.4,null,null);
insert into test values (1562074,1,to_date('2017-12-11','yyyy-mm-dd'),null,5,null);
insert into test values (1562074,1,to_date('2017-12-25','yyyy-mm-dd'),null,3,null);
insert into test values (1562074,1,to_date('2017-12-11','yyyy-mm-dd'),38,0,null);
commit;
运行:
select patient,visit_id,recording_date,sum(value1) value1,sum(value2) value2,sum(value3) value3 from test group by patient,visit_id,recording_date
结果: