当前位置:网站首页>[postgresql]postgresqlg use generate_ Series() function completes statistics
[postgresql]postgresqlg use generate_ Series() function completes statistics
2022-07-26 23:07:00 【just-do-it-zzj】
Catalog
1. demand
For example, the passing details of a gantry of the expressway are as follows :

demand :
It is necessary to count the total number of vehicles passing through the gantry by day , When there is no passing car, it is counted as 0, namely 7 month 13 If there is no record of the day, it should also be expressed as 0
with t1 as
(
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 day') as day
),
t2 (
select
pass_id,
capture_time,
to_char(capture_time,'yyyy-mm-dd')::date as capture_date,
grantry_code,
from sdi_op_toll_station_pass_detail_t
)
select day,grantry_code,count(pass_id) as cnt
from t1 left join t2
on t1.day=t2.capture_date
group by day,grantry_code;
2.generate_series function
| function | Parameter type | Return type | describe |
| generate_series(start, stop) | int or bigint | int or bigint( The type is the same as the parameter ) | Generate a numerical sequence , from start To stop, Step into one |
| generate_series(start, stop, step) | int or bigint | int or bigint( The type is the same as the parameter ) | Generate a numerical sequence , from start To stop, Step by step to step |
| generate_series(start, stop, step_interval) | timestamp or timestamp with time zone | timestamp or timestamp with time zone( The type is the same as the parameter ) | Generate a numerical sequence , from start To stop, Step by step to step |
3. example
3.1 interval 1 God
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 day')

3.2 interval 1 Hours
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 hour')

3.3 interval 1 minute
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 min')

边栏推荐
- Interview: your most impressive bug, for example
- kalibr标定realsenseD435i --多相机标定
- 思立微的反击:汇顶涉案屏下光学指纹专利被宣告无效
- 企业如何缓解物联网和工业物联网安全风险
- Ribbon load balancing
- Siliwei's counterattack: huiding's under screen optical fingerprint patent involved in the case was declared invalid
- 菜鸟网络面试【杭州多测师】【杭州多测师_王sir】
- Summary of shell related commands
- Apifox--比 Postman 还好用的 API 测试工具
- 苹果iPhone11系列的秘密武器:U1芯片或将开启超宽带时代
猜你喜欢

Database full stack Engineers (devdbops) have low down payment and high return, and pay after employment

Kt6368a Bluetooth chip development precautions and problem collection - long term update

Calendar documents implemented by several qwidgets
![[IO Development Notes] smart cloud intelligent watering device practice (1) - Basic demo implementation](/img/db/122cc54ad8b5b06c885d7455ecb034.png)
[IO Development Notes] smart cloud intelligent watering device practice (1) - Basic demo implementation
![[hcip] OSPF relationship establishment](/img/19/e03fea44f2908c7b585e7a1f87c075.png)
[hcip] OSPF relationship establishment

PostgreSQL and Navicat: the backbone of the database industry

Use ECs and OSS to set up personal network disk
![[hcip] OSPF route calculation](/img/1c/ee9eee2e723b850c401f7cddda1b27.png)
[hcip] OSPF route calculation

SQL 基础知识

Counter attack dark horse: devdbops training, give you the best courses!
随机推荐
基于C语言的页式文件系统
Recruit | PostgreSQL database R & D engineers every week, with an annual salary of 60+, high salary for famous enterprises, and challenge yourself!
Eureka基本使用
Let the program do one thing in one or more seconds
思立微的反击:汇顶涉案屏下光学指纹专利被宣告无效
Calendar documents implemented by several qwidgets
MySQL 数据的导入
【HCIP】OSPF 路由计算
数据库全栈工程师(DevDBOps)低首付、高回报,先就业后付款
What is Base64?
黑马瑞吉外卖之新增员工
New employees of black maredge takeout
芯鼎收购紫光控股!万业企业:全面转型集成电路!
DAO:OP 代币和不可转让的 NFT 致力于建立新的数字民主
Day07 MySql知识点再总结与多表查询
科研太忙无法顾家?陈婷:人生不能只有一个支点
面试:你印象最深的BUG,举个例子
Xinding acquires Ziguang holdings! Wanye enterprise: comprehensive transformation of integrated circuits!
Luo Xu talks with Siemens wanghaibin: advanced manufacturing requires benefits from Digitalization
电脑开机后内存占用过高(50%以上)