当前位置:网站首页>Offset function and windowing function
Offset function and windowing function
2022-07-04 19:57:00 【Lime Town in the sun】
Case study
Calculate the average next day retention rate of users
Create table statement
drop table if exists `user_profile`;
drop table if exists `question_practice_detail`;
drop table if exists `question_detail`;
CREATE TABLE `user_profile` (
`id` int NOT NULL,
`device_id` int NOT NULL,
`gender` varchar(14) NOT NULL,
`age` int ,
`university` varchar(32) NOT NULL,
`gpa` float,
`active_days_within_30` int ,
`question_cnt` int ,
`answer_cnt` int
);
CREATE TABLE `question_practice_detail` (
`id` int NOT NULL,
`device_id` int NOT NULL,
`question_id`int NOT NULL,
`result` varchar(32) NOT NULL,
`date` date NOT NULL
);
CREATE TABLE `question_detail` (
`id` int NOT NULL,
`question_id`int NOT NULL,
`difficult_level` varchar(32) NOT NULL
);
INSERT INTO user_profile VALUES(1,2138,'male',21,' Peking University, ',3.4,7,2,12);
INSERT INTO user_profile VALUES(2,3214,'male',null,' Fudan University ',4.0,15,5,25);
INSERT INTO user_profile VALUES(3,6543,'female',20,' Peking University, ',3.2,12,3,30);
INSERT INTO user_profile VALUES(4,2315,'female',23,' Zhejiang University ',3.6,5,1,2);
INSERT INTO user_profile VALUES(5,5432,'male',25,' Shandong University ',3.8,20,15,70);
INSERT INTO user_profile VALUES(6,2131,'male',28,' Shandong University ',3.3,15,7,13);
INSERT INTO user_profile VALUES(7,4321,'male',28,' Fudan University ',3.6,9,6,52);
INSERT INTO question_practice_detail VALUES(1,2138,111,'wrong','2021-05-03');
INSERT INTO question_practice_detail VALUES(2,3214,112,'wrong','2021-05-09');
INSERT INTO question_practice_detail VALUES(3,3214,113,'wrong','2021-06-15');
INSERT INTO question_practice_detail VALUES(4,6543,111,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(5,2315,115,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(6,2315,116,'right','2021-08-14');
INSERT INTO question_practice_detail VALUES(7,2315,117,'wrong','2021-08-15');
INSERT INTO question_practice_detail VALUES(8,3214,112,'wrong','2021-05-09');
INSERT INTO question_practice_detail VALUES(9,3214,113,'wrong','2021-08-15');
INSERT INTO question_practice_detail VALUES(10,6543,111,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(11,2315,115,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(12,2315,116,'right','2021-08-14');
INSERT INTO question_practice_detail VALUES(13,2315,117,'wrong','2021-08-15');
INSERT INTO question_practice_detail VALUES(14,3214,112,'wrong','2021-08-16');
INSERT INTO question_practice_detail VALUES(15,3214,113,'wrong','2021-08-18');
INSERT INTO question_practice_detail VALUES(16,6543,111,'right','2021-08-13');
INSERT INTO question_detail VALUES(1,111,'hard');
INSERT INTO question_detail VALUES(2,112,'medium');
INSERT INTO question_detail VALUES(3,113,'easy');
INSERT INTO question_detail VALUES(4,115,'easy');
INSERT INTO question_detail VALUES(5,116,'medium');
INSERT INTO question_detail VALUES(6,117,'easy');
select avg(if(DATEDIFF(date2,date1)=1,1,0)) as avg_ret from
(select date as date1,lead(date,1) over(partition by device_id order by date) as date2 from
(select DISTINCT device_id,date from question_practice_detail) as unique_date) as aa
A few problems to pay attention to :
1、if function
2、lead function ,lead( Column or function , How many lines in the future do not fill in the default 1, The default value defaults to null)
3、distinct Act on multiple columns , In fact, according to multiple columns to remove the heavy ;
4、 Subqueries use aliases
边栏推荐
- Cbcgptabwnd control used by BCG (equivalent to MFC TabControl)
- Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
- HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- 明明的随机数
- Chrome development tool: what the hell is vmxxx file
- Creation of JVM family objects
- Abc229 summary (connected component count of the longest continuous character graph in the interval)
- mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
- Cbcgpprogressdlg progress bar used by BCG
猜你喜欢
牛客小白月赛7 谁是神箭手

New wizard effect used by BCG

Multi table operation - external connection query

SSRS筛选器的IN运算(即包含于)用法

Pytorch学习(四)

欧拉函数

Euler function

BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)

做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!

Opencv functions and methods related to binary threshold processing are summarized for comparison and use
随机推荐
BCG 使用之CBCGPProgressDlgCtrl進度條使用
1008 Elevator(20 分)(PAT甲级)
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Hough transform Hough transform principle
线上数据库迁移的几种方法
New wizard effect used by BCG
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Dark horse programmer - software testing - stage 07 2-linux and database -09-24-linux command learning steps, wildcards, absolute paths, relative paths, common commands for files and directories, file
How to use async Awati asynchronous task processing instead of backgroundworker?
1008 elevator (20 points) (PAT class a)
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
@Data source connection pool exhaustion caused by transactional abuse
西门子HMI下载时提示缺少面板映像解决方案
HDU 1097 A hard puzzle
c# . Net MVC uses Baidu ueditor rich text box to upload files (pictures, videos, etc.)
Explicit random number
Actual combat simulation │ JWT login authentication
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize