当前位置:网站首页>Examples of unconventional aggregation
Examples of unconventional aggregation
2020-11-08 13:52:00 【osc_u9wft6hh】
1. Aggregate sum after enumeration grouping
【 example 1】 From the city GDP In the table , Separate statistics of municipalities directly under the central government 、 Per capita in first tier and second tier cities GDP. City GDP Some of the data in the table are as follows :
ID | City | GDP | Population |
1 | Shanghai | 32679 | 2418 |
2 | Beijing | 30320 | 2171 |
3 | Shenzhen | 24691 | 1253 |
4 | Guangzhou | 23000 | 1450 |
5 | Chongqing | 20363 | 3372 |
… | … | … | … |
【SPL Script 】
A | B | |
1 | =connect("db") | / Connect to database |
2 | =A1.query("select * from GDP") | / Check the city GDP surface |
3 | [["Beijing","Shanghai","Tianjing","Chongqing"].pos(?)>0,["Beijing","Shanghai","Guangzhou","Shenzhen"].pos(?)>0,["Chengdu","Hangzhou","Chongqing","Wuhan","Xian","Suzhou","Tianjing","Nanjing","Changsha","Zhengzhou","Dongguan","Qingdao","Shenyang","Ningbo","Kunming"].pos(?)>0] | / Enumerate municipalities 、 First tier cities and second tier cities |
4 | =A2.enum@r(A3,City) | / Group by city enumeration |
5 | =A4.new(A3(#):Area,~.sum(GDP)/~.sum(Population)*10000:CapitaGDP) | / Count the average person in each group GDP. It uses functions sum() Sum up |
A5 The results are as follows :
Area | CapitaGDP |
["Beijing","Shanghai","Tianjing","Chongqing"].pos(?)>0 | 107345.03 |
["Beijing","Shanghai","Guangzhou","Shenzhen"].pos(?)>0 | 151796.49 |
["Chengdu","Hangzhou","Chongqing","Wuhan","Xian","Suzhou","Tianjing","Nanjing","Changsha","Zhengzhou","Dongguan","Qingdao","Shenyang","Ningbo","Kunming"].pos(?)>0 | 106040.57 |
2. Merge overlapping time intervals
【 example 2】 Take the customer ANATR Merge order records with recurring time periods . Some data in the customer table are as follows :
OrderID | Customer | SellerId | OrderDate | FinishDate |
10308 | ANATR | 7 | 2012/09/18 | 2012/10/16 |
10309 | ANATR | 3 | 2012/09/19 | 2012/10/17 |
10625 | ANATR | 3 | 2013/08/08 | 2013/09/05 |
10702 | ANATR | 1 | 2013/10/13 | 2013/11/24 |
10759 | ANATR | 3 | 2013/11/28 | 2013/12/26 |
… | … | … | … | … |
【SPL Script 】
A | B | |
1 | =connect("db") | / Connect to data source |
2 | =A1.query("select * from Orders where Customer='ANATR'order by OrderDate") | / Select customers ANATR Order information for , Sort by order date |
3 | =A2.group@i(OrderDate>max(FinishDate[,-1])) | / When the order date is greater than the completion date of all previous orders, the new group |
4 | =A3.new(Customer,~.min(OrderDate):OrderDate,~.max(FinishDate):FinishDate) | / Using functions min() Calculate the earliest order date of each group as the order date , Using functions max Calculate the latest order date as the completion date |
A4 The results are as follows :
Customer | OrderDate | FinishDate |
ANATR | 2012/09/18 | 2012/10/17 |
ANATR | 2013/08/08 | 2013/09/05 |
ANATR | 2013/10/13 | 2013/11/24 |
ANATR | 2013/11/28 | 2013/12/29 |
… | … | … |
3. Count the number of satisfied conditions in group aggregation
【 example 4】 Ask for the number of students who failed in each subject in a class . Some of the data in the report form are as follows :
CLASS | STUDENTID | SUBJECT | SCORE |
Class one | 1 | English | 84 |
Class one | 1 | Math | 77 |
Class one | 1 | PE | 69 |
Class one | 2 | English | 81 |
Class one | 2 | Math | 80 |
… | … | … | … |
【SPL Script 】
A | B | |
1 | =connect("db") | / Connect to database |
2 | =A1.query("select * from Scores where CLASS='Class one'") | / Check the results of class one students |
3 | =A2.groups(SUBJECT; count(SCORE<60):FailCount) | / Group summary , It uses functions count() Count the number of people who failed |
A3 The results are as follows :
SUBJECT | FailCount |
English | 2 |
Math | 0 |
PE | 2 |
4. In a set of Boolean values , Aggregation performs logic and operations
【 example 5】 According to a series of primary school online teaching terminal Questionnaire , See if all students have access to mobile phones . The questionnaire and summary contents of each class are as follows :
ID | STUDENT_NAME | TERMINAL |
1 | Rebecca Moore | Phone |
2 | Ashley Wilson | Phone,PC,Pad |
3 | Rachel Johnson | Phone,PC,Pad |
4 | Emily Smith | Phone,Pad |
5 | Ashley Smith | Phone,PC |
6 | Matthew Johnson | Phone |
7 | Alexis Smith | Phone,PC |
8 | Megan Wilson | Phone,PC,Pad |
… | … | … |
【SPL Script 】
A | B | C | |
1 | =directory@ps("D:/Primary School") | / Recursively traversing directories , List all files | |
2 | for A1 | =file(A2).xlsimport@t() | / Circularly import the questionnaire of each class excel file |
3 | =B2.([TERMINAL,"Phone"].ifn().split@c().pos("Phone") > 0)|@ | / When the terminal in the questionnaire is not filled in, it is not considered that the mobile phone terminal is not supported , Using functions ifn() Guarantee that this item is true. | |
4 | =B3.cand() | / Using functions A.cand() Calculation B3 Are all members of true |
A4 The results are as follows :
Value |
false |
5. In a set of Boolean values , To perform logic or operations in aggregation
【 example 6】 Check with customers RATTC, stay 2014 Whether it has been ranked in the top three of monthly sales . The data in the sales table are as follows :
OrderID | Customer | SellerId | OrderDate | Amount |
10400 | EASTC | 1 | 2014/01/01 | 3063.0 |
10401 | HANAR | 1 | 2014/01/01 | 3868.6 |
10402 | ERNSH | 8 | 2014/01/02 | 2713.5 |
10403 | ERNSH | 4 | 2014/01/03 | 1005.9 |
10404 | MAGAA | 2 | 2014/01/03 | 1675.0 |
… | … | … | … | … |
【SPL Script 】
A | B | |
1 | =connect("db").query("select * from sales") | / Connect to data source , Read the sales list |
2 | =A1.select(year(OrderDate)==2014) | / elect 2014 Annual data |
3 | =A2.group(month(OrderDate)) | / take 2014 Year data are grouped by month |
4 | =A3.(~.groups(Customer; sum(Amount):Amount)) | / The members after grouping summarize the sales amount according to the customer group |
5 | =A4.new(~.top(-3; Amount):Top3) | / Cycle the data for each month , Before calculating the monthly sales 3 The customer |
6 | =A5.(Top3.(Customer).pos("RATTC")>0) | / Judge whether the top three of each month include customers RATTC |
7 | =A6.cor() | / Using functions A.cor() Calculation A6 Whether there are members of true |
A7 The results are as follows :
Value |
false |
《SPL CookBook》 There are more examples of relevant calculations in .
版权声明
本文为[osc_u9wft6hh]所创,转载请带上原文链接,感谢
边栏推荐
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- 关于update操作并发问题
- Rust: performance test criteria Library
- AQS解析
- Introduction to mongodb foundation of distributed document storage database
- Tight supply! Apple's iPhone 12 power chip capacity exposed
- Huawei has an absolute advantage in the 5g mobile phone market, and the market share of Xiaomi is divided by the market survey organization
- 3、 The parameters of the function
- What is the database paradigm
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
猜你喜欢
Tidb performance competition 11.02-11.06
软件开发中如何与人协作? | 每日趣闻
laravel8更新之速率限制改进
Q & A and book giving activities of harbor project experts
We made a medical version of the MNIST dataset, and found that the common automl algorithm is not so easy to use
Improvement of maintenance mode of laravel8 update
On monotonous stack
Rust : 性能测试criterion库
How to solve the difference between NAT IP and port IP
【Python 1-6】Python教程之——数字
随机推荐
Introduction to mongodb foundation of distributed document storage database
数据库连接报错之IO异常(The Network Adapter could not establish the connection)
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
Summary of template engine
Suitable for C / C + + novice learning some projects, do not give me to miss!
谷歌开源能翻译101种语言的AI模型,只比Facebook多一种
Bccoin tells you: what is the most reliable investment project at the end of the year!
最全!阿里巴巴经济体云原生实践!(附网盘链接)
漫画:寻找股票买入卖出的最佳时机(整合版)
laravel8更新之维护模式改进
Major changes in Huawei's cloud: Cloud & AI rises to Huawei's fourth largest BG with full fire
【Python 1-6】Python教程之——数字
一文读懂机器学习“数据中毒”
10个常见的软件架构模式
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
Why is Schnorr Signature known as the biggest technology update after bitcoin segwit
I used Python to find out all the people who deleted my wechat and deleted them automatically
Improvement of maintenance mode of laravel8 update
laravel8更新之速率限制改进
阿里撕下电商标签