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:
ticketrecords
columnName dataType
ticketid INT
orderid INT
paidtime DATETIME
reason VARCHAR
orderrecords
columnName dataType
orderid INT
orderstatus VARCHAR
mid INT
midrecords
columnName dataType
mid INT
brand VARCHAR
locality VARCHAR
city VARCHAR
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
