发送日期,打开的总数,上次打开的日期(如果有打开),总点击次数,最后点击的日期(如果有任何打开)
create table TBLA(Email text, SendID text, SendDate date, OpenDate date, ClickDate date);
insert into TBLA values("aaa@gmail.com", "ABCD1234", "8/1/2019",'1/8/2019',"8/1/2019");
insert into TBLA values("aaa@gmail.com", "ABCD1234", "8/1/2019",'2/8/2019',"");
insert into TBLA values("aaa@gmail.com", "ABCD1234", "8/1/2019",'3/8/2019',"8/3/2019");
insert into TBLA values("bbb@gmail.com", "ABCD1234", "8/1/2019",'1/8/2019',"");
insert into TBLA values("bbb@gmail.com", "ABCD1234", "8/1/2019",'2019/8/15',"8/15/2019");
insert into TBLA values("ccc@gmail.com", "ABCD1234", "8/1/2019","","");
insert into TBLA values("ddd@gmail.com", "ABCD1234", "8/1/2019","","");
insert into TBLA values("aaa@gmail.com", "xyz123", "8/2/2019","8/2/2019","8/2/2019");
insert into TBLA values("aaa@gmail.com", "xyz123", "8/2/2019","8/15/2019","");
insert into TBLA values("bbb@gmail.com", "xyz123", "8/2/2019","","");
insert into TBLA values("ccc@gmail.com", "xyz123", "8/2/2019","8/5/2019","8/5/2019");
select SendID," ", SendDate," ",count(OpenDate), " ", max(OpenDate), " ", count(ClickDate), " ", max(ClickDate)
from TBLA
where SendID = "ABCD1234" AND (OpenDate<>"" AND ClickDate<>"");
count(OpenDate)必须为5,max(OpenDate)必须为8/15/2019。 Count(ClickDate)必须为3。
答案 0 :(得分:1)
@nagarwal指出存在数据类型问题。日期字段被声明为日期,但接收字符串作为输入。 由于您是手动输入数据,因此我认为只需在日期中使用这种'YYYY-MM-DD'语法就可以解决问题。
答案 1 :(得分:0)
您可以使用to_date函数将dates列插入表格中,这将解决问题