In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
How to make the database statistics continuous with the same data? I believe that most people have not yet learned this skill, in order to let you learn, to give you a summary of the following content, do not say much, let's move on.
It is OK to use Group by to count the same data in a field in the database, but it is a bit troublesome to attach a sequence condition, for example, to count each player's winning streak or losing streak. Oracle has window analysis functions, which need multi-layer nesting plus advanced analysis functions to achieve. Mysql, Hive and other databases are not as powerful as Oracle, so it is more difficult to achieve. As the middle computing layer of application and database, aggregator can solve this kind of problem in a unified way. Let's take a look at a simple example. The table logs is as follows. What are the numbers that appear more than 3 times in a row in num?
+-+ +
| | id | num |
+-+ +
| | 1 | 1 |
| | 2 | 1 |
| | 3 | 1 |
| | 4 | 2 |
| | 5 | 1 |
| | 6 | 2 |
| | 7 | 2 |
+-+ +
The code for the aggregator looks like this
A1 $select id,num from logs2=A1.group@o (num) 3=A2.select (~ .len () > = 3). (~ .num)
A1:sql fetch
A2: grouped according to the same value of adjacent num
A3: select the same num at least three times in a row
If you want to know the maximum number of records with the same continuous value, the expression in A3 can be changed to = A2.max (~ .len ()).
Some requirements do not have the same value in order, but have the same trend in order. For example, to find out the records of those months with consecutive losses of three months or more, it is very simple to use the aggregator. Just change the adjacent data grouping rules from the equivalent condition to the trend condition. The code reference is as follows:
A1=db.query ("select * from income and expenditure statement order by month") 2=A1.group@o (income > expenditure). Select (~. Income = 3) .conj ()
The merging of attendance records and entry and exit status is a similar situation. E-commerce, logistics and banks often encounter such requirements as counting the total amount of continuous transactions, continuous landing days, continuous landing start and end time, interval days, and so on. These examples can be quickly implemented. In fact, there are many situations where it is very inconvenient to use SQL, but it is very simple to use the aggregator. If you are interested, you can take a look at the aggregator optimization SQL sample summary. The aggregator provides a Jdbc interface, and Java can be called directly, which is very convenient to use.
After reading the above, have you mastered the method of realizing the continuous same data in database statistics? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.