这就是我的价格表
Product_id prod_upc str_nbr Price
prod110010 4122067755 12 1.22
prod110010 4122067755 21 2.88
prod110010 4122063030 21 3.88
prod110010 4122063030 12 2.88
prod110010 4122063031 12 2.88
prod110010 4122063031 21 4.88
我有两个需要解决的问题
为所有商店的所有产品获得价格最低的UPC?基于以上数据,输出应为
prod110010 4122067755 12 1.22
获得每家商店所有产品的最低价格?基于以上数据,输出应为
prod110010 4122067755 12 1.22
prod110010 4122067755 21 2.88
我试过可能内部查询但没有任何效果,这里的任何SQL专家都请帮助。
我对特定商店的查询是:
SELECT DISTINCT t.product_id, t.prod_upc,t.str_nbr, t.MINVALUE
FROM ( SELECT dpc.product_id, hpd.prod_upc, str_nbr
, MIN(hpd.curr_retl_prc) OVER
(PARTITION BY dpc.product_id) MINVALUE
FROM prc_dta ) AS T
和全球:
SELECT DISTINCT t.product_id, t.prod_upc, t.str_nbr, t.MINVALUE
FROM ( SELECT dpc.product_id, hpd.prod_upc, hpd.str_nbr
, MIN(hpd.curr_retl_prc) OVER
(PARTITION BY dpc.product_id,hpd.str_nbr) MINVALUE
FROM prc_dta) AS T
答案 0 :(得分:0)
This query to get min price upc row :
select top 1 Product_id,prod_upc,str_nbr,Price from tbl where prod_upc=(select top 1 min(prod_upc) from tb1 ) order by Price asc
This query get all row of min price of upc:
select Product_id,prod_upc,str_nbr,Price from tbl where prod_upc=(select top 1 min(prod_upc) from tb1 ) order by Price asc