In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Several methods of grouping and summarizing the range of values in SQL
In the statistical work, we often encounter the situation of grouping and summarizing the value range of a quantity, such as
Assuming that the value of id is 100020000, and grouped according to the group distance 5000, we need to find 5000 below 5000, including 5000 and above 10000, including 10,000 and above 15000, including 15000 and 15000, and below 20000, including 20000.
Can be obtained by using the built-in rounding function ceil and division.
Select ceil (id/5000) f, count (1) cnt from T1 group by ceil (id/5000) order by 1
F CNT
--
1 5000
2 5000
3 5000
4 5000
But we can't deal with the unequal distance grouping with this method.
Suppose we want to find the count of less than 500500, including more than 1000, including 1000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000and 20000, including 20000, then the ceil function is powerless.
At this point, we can use custom functions.
Create or replace FUNCTION G2 (v NUMBER) RETURN INT IS
TYPE it IS TABLE OF INT
BEGIN
IF v > 0 AND v500 AND v1000 AND v5000 AND v0 AND id500 AND id1000 AND id5000 AND id0 AND id500 AND id1000 AND id5000 AND id
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.