当前位置:网站首页>Mysql/oracle takes the unique time as the boundary, and the sum is less than or equal to this time, and greater than this time
Mysql/oracle takes the unique time as the boundary, and the sum is less than or equal to this time, and greater than this time
2022-06-12 03:19:00 【Purple potato bun】
【 background 】 The project needs to group the number of users in hundreds of towns , This classification takes the cut-off time of a large number of users in each township as the dividing line , Statistics of user development before and after the launch , Here's the picture , You need statistics Less than equal 4 month 18 Data of the day and all data of subsequent days , I haven't encountered any similar problems before , Make a record here .

【 Ideas 】 I wanted to copy my homework on the Internet , But what we see is basically similar to the demand statistics based on time interval , Say your own thoughts , Because the cut-off time of different towns in the project is inconsistent , So first of all, we must determine the dividing line , That is, the date when the largest cut-off was found in different towns , Here, I first created a table to use as a dividing line
create table test_szxc_1 as
SELECT T.areaname,T.ctime,PV FROM test_SZXC T,
(SELECT T.areaname,MAX(PV) pp FROM test_SZXC T
group by T.areaname )a
where a.areaname = t.areaname
and a.pp = t.PVAnd then , Take one of the towns as an example , Find the data that is less than or equal to the cutover time , Then sum them in groups , Here is the bottom data I want to count
-- The bottom part
select t.areaname,sum(t.pv) from test_SZXC t,(select * from test_szxc_1 where areaname like '% Close the dam %')a
where
t.areaname = a.areaname
and
t.ctime <= a.ctime
group by areaname
Empathy , What is greater than this time is incremental data , Here I will directly handle the whole table ,
-- The incremental part
select t.areaname,sum(t.pv) from test_SZXC t,(select * from test_szxc_1 )a
where
t.areaname = a.areaname
and
t.ctime > a.ctime
group by areaname
Finally, it is found that this method is feasible , Just put the two parts of data together for processing , A column is added to distinguish
-- Data merging
select ' Bottom volume ' as category ,t.areaname,sum(t.pv) from test_SZXC t,(select * from test_szxc_1)a
where
t.areaname = a.areaname
and
t.ctime <= a.ctime
group by areaname
union all
select ' The incremental ' as category,t.areaname,sum(t.pv) from test_SZXC t,(select * from test_szxc_1 )a
where
t.areaname = a.areaname
and
t.ctime > a.ctime
group by areanameFinally, export
边栏推荐
- 【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression
- 安科瑞抗晃电产品在河北某化工项目的应用
- $LastExitCode=0, but $?= False in PowerShell. Redirecting stderr to stdout gives NativeCommandError
- Functions (arguments, formal parameters, bubbling)
- Final summary of addition, deletion, modification and query
- Requirements and business model analysis requirements 13 data modeling
- errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
- 2020-12-17
- Hudi of data Lake (14): basic concepts of Apache Hudi
- 微信小程序項目實例——體質計算器
猜你喜欢

I2C protocol overview

Hudi of data Lake (14): basic concepts of Apache Hudi

Convert py file to EXE file

Inverted string - two solutions

Demand and business model innovation - demand 8- interview
![[point cloud compression] variable image compression with a scale hyperprior](/img/d4/4084f64d20c8e622cddef2310d3b6c.png)
[point cloud compression] variable image compression with a scale hyperprior

2020-12-06

Unity3D中DrawCall、Batches、SetPassCall

Exemple de projet d'applet Wechat - calculatrice de constitution

Comparison of scores
随机推荐
余压监控系统在高层民用建筑的应用
Application of residual pressure monitoring system in high-rise civil buildings
[Business Research Report] forward looking report on urban renewal and development in China in 2021 - download link attached
central limit theorem
Laravel 8 selects JWT for interface verification
What is the commonly heard sub table of MySQL? Why does MySQL need tables?
[Business Research Report] 2021 global mobile game player white paper - download link attached
3768 string pruning (double pointer)
One article to show you how to understand the harmonyos application on the shelves
Computer configuration suggestions for learning modeling
2022 communication industry ultimate Exhibition Guide
Lighting Basics: optical model
[digital signal processing] correlation function (energy signal | cross correlation function of energy signal | autocorrelation function of energy signal)
2020-12-06
1 minute to understand the essential difference between low code and zero code
I2C协议概述
[digital signal processing] correlation function (power signal | cross correlation function of power signal | autocorrelation function of power signal)
Inverted string - two solutions
What is the difference between the gin framework of golang and the various methods of receiving parameters and various bindings?
无限循环判断方法;