在需要创建大量存储桶的情况下,是否存在比长case-when语句更有效的方法?
例如,我当前的查询将包裹重量分成多个桶(即1-5磅,5-15磅),最多70磅。但是,我现在需要创建70个不同的桶(每个lbs一个),其中任何重量在1-2磅之间的任何东西将圆形达到“2磅”,2-3磅之间的任何东西将圆形达到“3磅”等。有没有比用70个不同标准编写case-when语句更好的方法呢?
这是我当前的查询:
, CASE
WHEN round(orders.pkg_bill_weight,5) < 1
THEN '<1 lb'
WHEN round(orders.pkg_bill_weight,5) >= 1
AND round(orders.pkg_bill_weight,5) <
THEN '1-5 lb'
WHEN round(orders.pkg_bill_weight,5) >= 5
AND round(dosi.pkg_bill_weight,5) < 15
THEN '5-15 lb'
WHEN round(orders.pkg_bill_weight,5) >= 15
AND round(orders.pkg_bill_weight,3) < 30
THEN '15-30 lb'
WHEN round(orders.pkg_bill_weight,5) >= 30
AND round(orders.pkg_bill_weight,5) < 50
THEN '30-50 lb'
WHEN round(orders.pkg_bill_weight,5) >= 50
AND round(orders.pkg_bill_weight,5) < 70
THEN '50-70 lb'
WHEN round(orders.pkg_bill_weight,5) > 70
THEN '70+ lb'
ELSE 'Unknown' END as pkg_weight