You can help me write SQL to get the output or let me know how it can be done at Webi (4.1)
I am using Teradata 14. I have data in following format:
I have first two columns and I need to get third column using SQL/Recursive SQL.
The first two columns show mobile number and their call time to call center. I want to flag each call whether it is a repetitive call or not.
If the call from the same number is within 48 hours of first non repeated call , then I would flag it as repeated.
I have shown 17 rows below, in reality I have 3 millon rows to process. Could you please help.
Mobile Number Call Time Repeat/Non Repeat
A 2016/01/01 06:15:53 0
B 2016/01/01 18:29:29 0
B 2016/01/01 18:33:45 1
B 2016/01/01 19:14:02 1
B 2016/01/01 20:28:38 1
B 2016/01/05 20:51:48 0
B 2016/01/05 20:53:19 1
B 2016/01/10 20:54:28 0
C 2016/01/01 22:45:41 0
D 2016/01/02 17:33:12 0
E 2016/01/02 00:15:08 0
F 2016/01/01 19:51:09 0
F 2016/01/01 20:06:06 1
F 2016/01/01 21:24:47 1
F 2016/01/02 09:21:08 1
F 2016/01/03 20:21:08 0
F 2016/01/05 09:21:08 1
Note: The 0 for F on 3rd Jan is because it is NOT withing 48 hours of the previous 0 which is for 2016/01/01 19:51:09
The repeated calls are ignored as if they don’t exist.
Here is script to create the above sample data:
CREATE TABLE TestTable
(
Mobile VARCHAR(10),
CallTime TIMESTAMP
);
INSERT INTO TestTable VALUES (‘A’,TO_TIMESTAMP( ‘2016-01-01 06:15:53’, ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-01 18:29:29’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-01 18:33:45’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-01 19:14:02’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-01 20:28:38’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-05 20:51:48’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-05 20:53:19’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘B’,TO_TIMESTAMP( ‘2016-01-10 20:54:28’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘C’,TO_TIMESTAMP( ‘2016-01-01 22:45:41’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘D’,TO_TIMESTAMP( ‘2016-01-02 17:33:12’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘E’,TO_TIMESTAMP( ‘2016-01-02 00:15:08’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘F’,TO_TIMESTAMP( ‘2016-01-01 19:51:09’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘F’,TO_TIMESTAMP( ‘2016-01-01 20:06:06’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘F’,TO_TIMESTAMP( ‘2016-01-01 21:24:47’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘F’,TO_TIMESTAMP( ‘2016-01-02 09:21:08’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘F’,TO_TIMESTAMP( ‘2016-01-03 20:21:08’ , ‘YYYY-MM-DD HH24:MI:SS’));
INSERT INTO TestTable VALUES (‘F’,TO_TIMESTAMP( ‘2016-01-05 09:21:08’ , ‘YYYY-MM-DD HH24:MI:SS’));
Raghvendra Deshpande (BOB member since 2008-05-26)