当前位置:网站首页>[postgresql]postgresqlg使用enerate_series() 函数补全统计
[postgresql]postgresqlg使用enerate_series() 函数补全统计
2022-07-26 22:12:00 【just-do-it-zzj】
目录
1.需求
比如高速公路的某个门架的过车明细数据如下:

需求:
需要按天统计通过该门架的过车总数量,没有过车的时候统计为0,即7月13日没有记录也要在报表中表示为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函数
| 函数 | 参数类型 | 返回类型 | 描述 |
| generate_series(start, stop) | int 或 bigint | int 或 bigint(与参数类型相同) | 生成一个数值序列,从start 到 stop,步进为一 |
| generate_series(start, stop, step) | int 或 bigint | int 或 bigint(与参数类型相同) | 生成一个数值序列,从start 到 stop,步进为step |
| generate_series(start, stop, step_interval) | timestamp or timestamp with time zone | timestamp 或 timestamp with time zone(与参数类型相同) | 生成一个数值序列,从start 到 stop,步进为step |
3.实例
3.1 间隔1天
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 day')

3.2 间隔1小时
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 hour')

3.3 间隔1分钟
select generate_series('2022-07-10'::date,'2022-07-17'::date,'1 min')

边栏推荐
- The JSON string is converted into a JSON object, the value of a key is obtained, and whether a key exists is judged
- y78.第四章 Prometheus大厂监控体系及实战 -- prometheus的服务发现机制(九)
- sql多表查询的练习
- Those environment configurations and plug-ins of idea
- 利用Go制作微信机器人(一)发送消息
- 商汤科技CEO徐立:公司估值已超70亿美元,不急于上市
- Is test development development development?
- Luo Xu talks with Siemens wanghaibin: advanced manufacturing requires benefits from Digitalization
- 7.27 watch first | openeuler is ambitious, open source Huizhi creates the future - the most detailed agenda of the Euler sub forum of the open atom global open source summit is released
- Which is better, caiqian school or qiniu school? Is it safe
猜你喜欢

Calendar documents implemented by several qwidgets

APP信息侦察&夜神模拟器Burp抓包配置

程序员成长第二十九篇:如何激励员工?
What if redis memory is full? This is the right way to deal with it

黑马瑞吉外卖之新增员工

Leetcode 121: the best time to buy and sell stocks

Embedded SIG | 分布式软总线

Shardingsphere JDBC keyword problem

测试开发是开发吗?

Apifox--比 Postman 还好用的 API 测试工具
随机推荐
Reinforcement learning weekly 55: lb-sgd, msp-drl & robust reinforcement learning against
[hcip] OSPF relationship establishment
KT6368A蓝牙芯片开发注意事项以及问题集锦--长期更新
what crlf mean
Height collapse caused by floating
Xinding acquires Ziguang holdings! Wanye enterprise: comprehensive transformation of integrated circuits!
《强化学习周刊》第55期:LB-SGD、MSP-DRL & 对抗鲁棒强化学习
New thrust of Moore's law, detailed explanation of Intel Advanced Packaging Technology!
Module 8 (message queue MySQL table storing message data)
继关闭苏州厂之后,欧姆龙东莞厂宣布解散,2000多人面临失业!
杰理下载器强制下载工具的使用介绍_AC695N696NAD14AD15全系列支持
what crlf mean
2022-07-26:以下go语言代码输出什么?A:5;B:hello;C:编译错误;D:运行错误。 package main import ( “fmt“ )
测试开发是开发吗?
基于C语言设计的增量型安全文件系统 SFS
Systemctl command
kalibr标定realsenseD435i --多相机标定
Makefile related syntax summary (openc910)
Weilai cup 2022 Niuke summer multi school training camp 1
Embedded sig | distributed soft bus