Hi All,
Hope you are doing well!...I am working on a table that has the communications that happen between a customer who buys the product online from Amazon and the company which hosts the product on Amazon for a specific order...These communications happen as the customer is not satisfied with the product for some reason...I am trying to capture the following :
-
Number of communications that happen from the customer end - this can be identified in the title column with the line that contains 'Inquiry from Amazon Customer' or 'Inquiry from Customer'
-
Number of communications that happen from the company end -this can be identified in the title column with the line that contains 'Customer - '
-
The average and the maximum time gap between all customer and company communications for every order (in days and hours)..
I am looking at all the above for every order before the occurrence of the line that contains
atoz-guarantee-no-reply@amazon.com
Can you please help here!..Please find the DDL below:(both the input table and output table)
Create table #orders
(orderid varchar(20),
created DATETIME2,
title varchar(2000)
)
drop table #orders
insert into #orders values
('3635763','2019-01-19 23:10:34:345','Inquiry from Amazon Customer '),
('3635763','2019-01-17 21:14:07:348','customer - order is getting delayed '),
('3635763','2019-01-17 21:20:34:789','Shipping Inquiry from Amazon Customer '),
('3635763','2019-01-18 04:41:56:902','Claim filed to : atoz-guarantee-no-reply@amazon.com'),
('3635763','2019-02-17 14:43:36:567','Inquiry from Amazon Customer-following up again '),
('3635763','2019-02-18 15:13:29:456','customer - Final steps in sending out the order'),
('4003456','2019-01-02 03:46:56:341','Tracking order revision sent '),
('4003456','2019-01-04 06:27:43:342','Inquiry from Amazon Customer '),
('4003456','2019-01-06 06:27:32:267','Vendor: Sent parts Info '),
('4003456','2019-01-08 06:27:56:321','Customer - the order will be sent '),
('4003456','2019-01-10 08:30:44:316','Claim filed to : atoz-guarantee-no-reply@amazon.com'),
('4003456','2019-01-12 08:30:55:412','Customer - Reaching out again'),
('4003456','2019-01-13 08:30:33:512','Amazon:Atoz reponse regarding claim ')
CREATE TABLE #OUTPUT
(ORDERID varchar(20),
Numberoftimescustomerhascontacted int,
Numberoftimesourcompanyhascontacted int,
averagetimegapofcommunicationbetweencustomerandcompanyindays float,
maximumtimebetweencommunications float
)
insert into #output values
('3635763','2','1','3.96','7.9'),
('4003456','1','1','3.99','3.99')
Thanks,
Arun