I have to write Hive SQL.
I want to find the lowest price for each category. I want to get one row for each category with the category ID, the product ID, the price (lowest price), and the image url columns. In the example below, we finally need two rows.
Help me. Thank you.
"category_product_match" table
category_id product_id
1001 500001
1001 500002
1002 500101
1002 500102
1002 500103
"product_info" table
prd_id price img_url
500001 29000 /app/url/img/500001.jpg
500002 29500 /app/url/img/500002.jpg
500101 8100 /app/url/img/500101.jpg
500102 8100 /app/url/img/500102.jpg
500103 8500 /app/url/img/500103.jpg
You can use window functions:
use Min aggregate function with inner join and group by with category id
Demo here Sqlfiddle