我试图编写一个Select
语句,将acolumn
值增加50,但是范围最终可能是200000,所以我不能在case语句中手动完成所有操作。
类似的东西,但不是手动编写increments
Select count(order_id) as order_count,
case when revenue between 0 and 50 then ‘$50’
when order_value between 51 and 100 then ‘$100’
else ‘over $101’
end as revenue_bucket
from Orders
group by 2
最佳答案
将revenue
转换为bucket值,然后从中生成string:
SELECT count(order_id) AS order_count,
'$' || ((((revenue - 0.01)/50)::int + 1) * 50)::text AS revenue_bucket
FROM Orders
GROUP BY 2;
这显然远远超过20万美元。
关于sql - select语句中的SQL增量列值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31558294/