当前位置:网站首页>Oracle queries grouped by time
Oracle queries grouped by time
2022-07-03 07:49:00 【A reserved and calm man】
1. By year
Group the query by year and arrange the results in order
select to_char(SLRQ,'yyyy') ,count(*)from mv_ywst_fa group by to_char(SLRQ,'yyyy') ORDER BY to_char(SLRQ,'yyyy')

2. Query by quarter
Group the query by quarter and arrange the results in order
select to_char(SLRQ,'yyyy-Q') ,count(*)from mv_ywst_fa group by to_char(SLRQ,'yyyy-Q') ORDER BY to_char(SLRQ,'yyyy-Q')

3. Query by month
Group the query by month and arrange the results in order
select to_char(SLRQ,'yyyy-mm') ,count(*)from mv_ywst_fa group by to_char(SLRQ,'yyyy-mm') ORDER BY to_char(SLRQ,'yyyy-mm')

4. Query by week
After grouping the query by week, arrange the results in order
select to_char(SLRQ,'yyyy-IW') ,count(*)from mv_ywst_fa group by to_char(SLRQ,'yyyy-IW') ORDER BY to_char(SLRQ,'yyyy-IW')

5. Group queries and merge results
take 7 Views are grouped and queried by quarter and the results are consolidated
SELECT time,sum(amount) amount FROM
(
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_hs WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
union all
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_gc WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
union all
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_xz WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
union all
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_yx WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
union all
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_tj WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
union all
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_fa WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
union all
select to_char(SLRQ,'yyyy-Q') as time,count(*) as amount from (SELECT * FROM mv_ywst_yd WHERE SLRQ between to_date('2012-1-1 00:00:00','yyyy-mm-dd hh24-mi-ss')
and to_date('2012-12-31 23:59:59','yyyy-mm-dd hh24-mi-ss')) group by to_char(SLRQ,'yyyy-Q')
) GROUP BY time
边栏推荐
- Huawei switch basic configuration (telnet/ssh login)
- Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
- Robots protocol
- PAT甲级 1027 Colors in Mars
- 微软安全响应中心
- [MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
- 【MySQL 12】MySQL 8.0.18 重新初始化
- go语言-循环语句
- What is a data type? What is the use of data types?
- PHP wechat red packet grabbing algorithm
猜你喜欢

Lucene hnsw merge optimization

Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction

Go language foundation ----- 03 ----- process control, function, value transfer, reference transfer, defer function
![[MySQL 12] MySQL 8.0.18 reinitialization](/img/e1/9874df18bbc8d80c3c5c5fe39aefc9.png)
[MySQL 12] MySQL 8.0.18 reinitialization

Robots protocol

Go language foundation ----- 06 ----- anonymous fields, fields with the same name

技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验

Harmonyos third training notes

Research shows that breast cancer cells are more likely to enter the blood when patients sleep

Lucene introduces NFA
随机推荐
OSPF experiment
什么是数据类型?数据类型有什么用?
go语言-循环语句
Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass
What to do after the browser enters the URL
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Robots protocol
技术干货|利用昇思MindSpore复现ICCV2021 Best Paper Swin Transformer
Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Redis查看客户端连接
Differences between tp3.2 and tp5.0
技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
Research shows that breast cancer cells are more likely to enter the blood when patients sleep
GoLang之结构体
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
PAT甲级 1027 Colors in Mars
yarn link 是如何帮助开发者对 NPM 包进行 debug 的?