将 product_id 放入价格范围
Place product_id into a price range
我想为给定的 product_id 添加一个价格范围,增量为 500。例如,价格为 450 的产品应具有 500 的价格范围,而价格为 2450 的产品应具有 2000 的价格范围。
主要table
product_id price
32828 2593
23224 456
34344 1000
58283 2420
43585 550
输出table
product_id price price_range
32828 2593 3000
23224 456 500
34344 1000 1000
58283 2420 2000
43585 550 600
您可以使用 case when 来管理您喜欢的范围
select case when price between 0 and 500 then 500
when price between 501 and 600 then 600
when price between 601 and 1500 then 1000
when price between 1501 and 2500 then 2000
END range
我想为给定的 product_id 添加一个价格范围,增量为 500。例如,价格为 450 的产品应具有 500 的价格范围,而价格为 2450 的产品应具有 2000 的价格范围。
主要table
product_id price
32828 2593
23224 456
34344 1000
58283 2420
43585 550
输出table
product_id price price_range
32828 2593 3000
23224 456 500
34344 1000 1000
58283 2420 2000
43585 550 600
您可以使用 case when 来管理您喜欢的范围
select case when price between 0 and 500 then 500
when price between 501 and 600 then 600
when price between 601 and 1500 then 1000
when price between 1501 and 2500 then 2000
END range