当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- PMP考试通过心得分享
- 我用 Python 找出了删除我微信的所有人并将他们自动化删除了
- GopherChina 2020大会
- Q & A and book giving activities of harbor project experts
- 区块链周报:数字货币发展写入十四五规划;拜登邀请MIT数字货币计划高级顾问加入总统过渡团队;委内瑞拉推出国营加密交易所
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- RestfulApi 学习笔记——父子资源(四)
- The first open source Chinese Bert pre training model in the financial field
- Improvement of maintenance mode of laravel8 update
猜你喜欢
【Python 1-6】Python教程之——数字
Ali! Visual computing developer's series of manuals (with internet disk link)
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
PMP experience sharing
Shell uses. Net objects to send mail
Introduction to mongodb foundation of distributed document storage database
Why is Schnorr Signature known as the biggest technology update after bitcoin segwit
供货紧张!苹果被曝 iPhone 12 电源芯片产能不足
Rust: performance test criteria Library
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
随机推荐
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
在51CTO学院Get到PMP证书
The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
Flink from introduction to Zhenxiang (10. Sink data output elasticsearch)
谷歌开源能翻译101种语言的AI模型,只比Facebook多一种
Share the experience of passing the PMP examination
android基础-CheckBox(复选框)
10个常见的软件架构模式
2035 we will build such a country
I used Python to find out all the people who deleted my wechat and deleted them automatically
This year's salary is 35W +! Why is the salary of Internet companies getting higher and higher?
软件开发中如何与人协作? | 每日趣闻
大龄程序员没有出路吗?
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
啥是数据库范式
Implementation of verification code recognition in Python opencv pytesseract
后端程序员必备:分布式事务基础篇
LeanCloud 十月变化
Improvement of maintenance mode of laravel8 update
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)