当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Golang ICMP协议探测存活主机
- OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
- 为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
- 10 common software architecture patterns
- AQS解析
- 漫画|讲解一下如何写简历&项目
- Q & A and book giving activities of harbor project experts
- Enabling education innovation and reconstruction with science and technology Huawei implements education informatization
- How to cooperate with people in software development? |Daily anecdotes
- 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
猜你喜欢
你的云服务器可以用来做什么?云服务器有什么用途?
[Python 1-6] Python tutorial 1 -- number
What is the database paradigm
浅谈单调栈
Q & A and book giving activities of harbor project experts
OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
原创 | 数据资产确权浅议
What can your cloud server do? What is the purpose of cloud server?
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
随机推荐
On the confirmation of original data assets
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
What can your cloud server do? What is the purpose of cloud server?
Tips and skills of CSP examination
重返全球第三,小米做对了什么?
Eight ways to optimize if else code
python基础教程python opencv pytesseract 验证码识别的实现
金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
laravel8更新之速率限制改进
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
How to write a resume and project
STM32CubeIDE下载安装-GPIO基本配置操作-Debug调试(基于CMSIS DAP Debug)
[Python 1-6] Python tutorial 1 -- number
AI周报:允许“员工自愿降薪”;公司回应:员工内心高兴满意;虎牙HR将员工抬出公司;瑞典禁用华为中兴5G设备
分布式文档存储数据库之MongoDB基础入门
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
漫画|讲解一下如何写简历&项目
Android Basics - check box
数据库连接报错之IO异常(The Network Adapter could not establish the connection)
【Python 1-6】Python教程之——数字