Company: Pocketpills Backend Engineer Intern Oncampus_18july
Difficulty: medium
You are given two tables, Customers and Orders . For every customer, find that customer's second most recent order . Orders are ranked by order_date , most recent first. Only customers who have at least two orders appear in the result. Report customer_id , customer_name , order_id , order_date and amount , ordered by customer_id ascending. If two orders of the same customer share the same order_date , the one with the larger order_id is treated as the more recent of the two. Table Schema CREATE TABLE Customers ( customer_id INT PRIMARY KEY, customer_name VARCHAR(100) ); CREATE TABLE Orders ( order_id INT PRIMARY KEY, customer_id INT, order_date DATE, amount INT ); Reference SQL result customer_id | customer_name | order_id | order_date | amount 1 | Alice | 102 | 2024-02-15 | 300 2 | Bob | 105 | 2024-02-20 | 100 How this question is graded Your program is run as a complete program: it reads the two tables from standard input and writes the result rows to standard output . Write the quer