数据如下表:
CREATE TABLE test
(
bill_no varchar(100) null,
flow_type varchar(100) null,
start_time varchar(100) null,
end_time varchar(100)null,
op_name varchar(100) null,
status int null
)
INSERT INTO test(bill_no,flow_type,start_time,end_time,op_name,status) values('dj_001','f001','2020-05-22 14:42:27','2020-05-22 14:42:27','阿红',11);
INSERT INTO test(bill_no,flow_type,start_time,end_time,op_name,status) values('dj_001','f001','2020-05-22 14:44:27','2020-05-22 14:44:27','小明',11);
INSERT INTO test(bill_no,flow_type,start_time,end_time,op_name,status) values('dj_001','f001','2020-05-22 14:44:27','2020-05-22 14:45:08','小明',99);
INSERT INTO test(bill_no,flow_type,start_time,end_time,op_name,status) values('dj_001','f002','2020-05-22 14:45:08','2020-05-22 14:45:08','莉莉',11);
INSERT INTO test(bill_no,flow_type,start_time,end_time,op_name,status) values('dj_001','f002','2020-05-22 14:45:08','2020-05-22 14:45:08','佳佳',11);
INSERT INTO test(bill_no,flow_type,start_time,end_time,op_name,status) values('dj_001','f002','2020-05-22 14:45:08','2020-05-22 18:18:22','佳佳',99);
统计结果:
统计说明:
根据bill_no字段统计对应的数据。
结果中的start_time取对应flow_type的最小start_time
结果中的end_time取对应flow_type的,且status=99 的最大end_time
结果中的op_name取对应flow_type的,且status=99 的最大op_name
上图结果用sql如何写?????
你这有点类似行列转换了,不单单是统计。。。