I'm having trouble with an SQL problem on HackerRank (so no rank or window functions):
Product_Id Product_Name Category Price Discount Available
1 P-1 C-5 720 10 1
2 P-2 C-1 935 17 1
3 P-3 C-2 588 19 1
4 P-4 C-4 619 5 0
5 P-5 C-1 803 16 1
I want to know which product is on the maximum discount for each category. In the case of multiple products having the same maximum discount within a category, print the product with the minimum product_id.
Sample Output
C-1 2 17
C-2 3 19
C-4 4 5
C-5 1 10
In this SQL Fiddle, I've put here what I've tried so far. I'm not sure how to get the product for the maximum discount. Also, how can I handle if there are multiple products with the same maximum discount?