本文介绍了select语句中的SQL增量列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写 Select
语句,该语句将列
的值增加50,但是范围可以最终是200,000,所以我不能在case语句中手动完成所有操作。
I'm trying to write a Select
statement that increments a column
value by 50, but the range can end up being 200,000 so I can't do it all in a case statement manually.
与此类似,但不是手动编写增量
Something similar to this, but instead of manually writing the 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
推荐答案
打开您的收入
到存储桶值中,然后从中取出字符串:
Turn your revenue
into the bucket value, then make string out of it:
SELECT count(order_id) AS order_count,
'$' || ((((revenue - 0.01)/50)::int + 1) * 50)::text AS revenue_bucket
FROM Orders
GROUP BY 2;
显然,这远远超过了$ 200,000。
This obviously runs well past $200,000.
这篇关于select语句中的SQL增量列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!