将product_id放入价格范围内

问题描述 投票:0回答:1

我想为给定的product_id添加价格范围(以500为增量)。例如,价格为450的产品的价格范围应为500,而价格为2450的产品的价格范围应为2000。

主表

product_id       price

32828            2593
23224            456
34344            1000
58283            2420
43585            550

输出表

product_id       price    price_range

32828            2593     3000   
23224            456      500    
34344            1000     1000
58283            2420     2000
43585            550      600

sql presto
1个回答
0
投票

您可以根据需要使用案例来管理范围

  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
© www.soinside.com 2019 - 2024. All rights reserved.