惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
美团技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
雷峰网
雷峰网
P
Proofpoint News Feed
IT之家
IT之家
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
T
The Blog of Author Tim Ferriss
月光博客
月光博客
V
Visual Studio Blog
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
Project Zero
Project Zero
U
Unit 42
T
Tor Project blog
Scott Helme
Scott Helme
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
InfoQ
Cloudbric
Cloudbric
P
Proofpoint News Feed
The Cloudflare Blog
H
Heimdal Security Blog
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
Attack and Defense Labs
Attack and Defense Labs
有赞技术团队
有赞技术团队
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
博客园 - 【当耐特】
Security Latest
Security Latest
The Register - Security
The Register - Security
F
Fortinet All Blogs
I
Intezer
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
NISL@THU
NISL@THU
T
Tenable Blog

博客园 - FilyCks

SQL动态条件查询例子 日期格式化函数 解决日志文件满造成的无法写入问题 数据库的日志文件 Delphi制作DLL SQLSERVER 日期函数及取当天数据 SQL语句导入导出大全 日期数据处理 FastReport(5) FastReport(4) FastReport(3) FastReport(2) FastReport(1) 游标嵌套(个人笔记) FastReport 的初学感悟 查询表(个人笔记) 图片转换和读取(个人笔记) 游标的一些例子 自己研究出来的第一个游标
按时间段统计数据(1)
FilyCks · 2008-03-17 · via 博客园 - FilyCks

有这样一个表table1,两个字段,createtime和value,如下

2007-07-09   07:00:01           90
2007-07-09   08:05:31           78
2007-07-09   14:00:00           95
2007-07-09   21:15:01           20
2007-07-10   22:23:08           10

这个表每天,每分钟都会有数据。统计每天0点到8点,21点到23,value的总和,其它时间段不要。

--测试数据
create   table   t4(cdate   date,cnum   int)
insert   into   t4
select   to_date( '2007-07-09   07:00:01 ', 'yyyy-mm-dd   hh24:MI:SS) '),90   from   dual   union   all  
select   to_date( '2007-07-09   08:05:31 ', 'yyyy-mm-dd   hh24:MI:SS) '),78   from   dual   union   all
select   to_date( '2007-07-09   14:00:00 ', 'yyyy-mm-dd   hh24:MI:SS) '),95   from   dual   union   all
select   to_date( '2007-07-09   21:15:01 ', 'yyyy-mm-dd   hh24:MI:SS) '),20   from   dual   union   all
select   to_date( '2007-07-10   22:23:08 ', 'yyyy-mm-dd   hh24:MI:SS) '),10   from   dual;
--执行查询
select   to_char(cdate, 'yyyy-mm-dd '),
sum(case   when   to_number(to_char(   cdate, 'hh24 '   ))> 0   and   to_number(to_char(   cdate, 'hh24 '   )) <=8   then   cnum   else   0   end)   "0~8 ",
sum(case   when   to_number(to_char(   cdate, 'hh24 '   ))> 21   and   to_number(to_char(   cdate, 'hh24 '   )) <=23   then   cnum   else   0   end)   "21~23 "
from   t4
group   by   to_char(cdate, 'yyyy-mm-dd ')
--查询结果
2007-07-09 168 0
2007-07-10 0 10