Procedure returning result set
SQL
Medium
2 views
Problem Description
Create sp_top_customers(p_n) that returns top N customers by total spend.
Input Format
SQL procedure
Output Format
Procedure created
Sample Test Case
Input:
Orders(customer_id, total_amount)
Output:
Procedure created
Constraints
Return result set
Official Solution
CREATE PROCEDURE sp_top_customers(IN p_n INT) BEGIN SELECT customer_id, SUM(total_amount) AS spend FROM Orders GROUP BY customer_id ORDER BY spend DESC LIMIT p_n; END;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!