Question: You need to write an SQL query to analyze the payment processing time for each order. Payment Processing Time: The time it took ( in

You need to write an SQL query to analyze the payment processing time for each order.
Payment Processing Time: The time it took (in minutes) to process the payment for the order. This should be calculated as the difference between the paid time of the current ticket and the paid time of the previous ticket for the same order. If there is no previous ticket for the same order, the payment processing time should be considered as NULL for that ticket.
Average Payment Processing Time: The average payment processing time (in minutes) for all tickets of the same order. This should be calculated as a window function, averaging the payment processing times for all tickets of the same order. Your query should return results for all tickets, ordered by Order ID and Paid Time.
Tables Schema as Below:
ticket_records
columnName dataType
ticket_id INT
order_id INT
paid_time DATETIME
reason VARCHAR(255)
order_records
columnName dataType
order_id INT
order_status VARCHAR(50)
mid INT
mid_records
columnName dataType
mid INT
brand VARCHAR(50)
locality VARCHAR(50)
city VARCHAR(50)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!