当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 供货紧张!苹果被曝 iPhone 12 电源芯片产能不足
- laravel8更新之速率限制改进
- Tidb performance competition 11.02-11.06
- 我用 Python 找出了删除我微信的所有人并将他们自动化删除了
- Workers, workers soul, draw lifelong members, become a person!
- AI weekly: employees are allowed to voluntarily reduce salary; company response: employees are happy and satisfied; tiger tooth HR takes employees out of the company; Sweden forbids Huawei ZTE 5g equi
- Powershell 使用.Net对象发送邮件
- When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
- Eight ways to optimize if else code
- PMP心得分享
猜你喜欢

Powershell 使用.Net对象发送邮件

Workers, workers soul, draw lifelong members, become a person!
![[Python 1-6] Python tutorial 1 -- number](/img/3b/00bc81122d330c9d59909994e61027.jpg)
[Python 1-6] Python tutorial 1 -- number

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom

PMP experience sharing

This paper analyzes the top ten Internet of things applications in 2020!

Stm32uberide download and install - GPIO basic configuration operation - debug (based on CMSIS DAP debug)

新型存算一体芯片诞生,利好人工智能应用~

Station B STM32 video learning

Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
随机推荐
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
Restfulapi learning notes -- father son resources (4)
AQS解析
最全!阿里巴巴经济体云原生实践!(附网盘链接)
Rust: performance test criteria Library
Blockchain weekly: the development of digital currency is written into the 14th five year plan; Biden invited senior adviser of MIT digital currency program to join the presidential transition team; V
漫画:寻找股票买入卖出的最佳时机(整合版)
2020-11-05
Suitable for C / C + + novice learning some projects, do not give me to miss!
非常规聚合问题举例
后端程序员必备:分布式事务基础篇
nat转换的ip跟端口ip不相同的解决方法
We made a medical version of the MNIST dataset, and found that the common automl algorithm is not so easy to use
The most complete! Alibaba economy cloud original practice! (Internet disk link attached)
小米、OPPO在欧洲市场继续飙涨,小米更是直逼苹果
android基础-CheckBox(复选框)
模板引擎的整理归纳
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
On the software of express delivery cabinet and deposit cabinet under Windows
Interpretation of deepmind's latest paper: the causal reasoning algorithm in discrete probability tree is proposed for the first time