oracle 需要使用sql developer在oracle db上按日期计算记录和分组计数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13146782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:35:56  来源:igfitidea点击:

Need to count records and group count by date on oracle db using sql developer

oraclecountoracle10ggroup-byoracle-sqldeveloper

提问by camarokris

I have a table like the following

我有一张像下面这样的表

   ID                created    sent    type
-----------------------------------------------------
0001463583000051783  31-JUL-12  1   270
0081289563000051788  01-AUG-12  1   270
0081289563000051792  01-AUG-12  1   270
0081289563000051791  01-AUG-12  1   270
0081289563000051806  01-AUG-12  1   270
0001421999000051824  06-AUG-12  1   270
0001421999000051826  06-AUG-12  1   270
0001464485000051828  06-AUG-12  1   270
0082162128000051862  09-AUG-12  2   278
0082162128000051861  09-AUG-12  2   278
0022409222082910259  09-AUG-12  3   278

I would like to have the following for output

我想有以下输出

created     Count
---------------------
31-JUL-12   1
01-AUG-12   4
06-AUG-12   3
09-AUG-12   3

How hard would it be to accomplish this using SQL Developer on Oracle 10g

在 Oracle 10g 上使用 SQL Developer 实现这一目标有多难

I have tried several queries to generate such a table and in the end it does not group the count by date just gives me a '1' for the count when we average 5000-10000 transactions daily. Im probably over complicating it. But i would like something simple where i can pull the amount of transactions on a daily basis within a date range.

我已经尝试了几个查询来生成这样一个表,最后它没有按日期对计数进行分组,当我们每天平均处理 5000-10000 笔交易时,它只是给我一个“1”的计数。我可能把它复杂化了。但我想要一些简单的东西,我可以在一个日期范围内每天提取交易量。

what is happening currently when i run my queries is

当我运行查询时,当前正在发生的事情是

created     Count
---------------------
31-JUL-12   1
01-AUG-12   1
01-AUG-12   1
01-AUG-12   1
01-AUG-12   1
06-AUG-12   1
06-AUG-12   1
06-AUG-12   1
09-AUG-12   1
09-AUG-12   1
09-AUG-12   1

回答by A.B.Cade

I managed to get this results with this query:

我设法通过这个查询得到了这个结果:

select trunc(created), count(*)
from table1
group by trunc(created)

Note the truncfunction, even if you don't display it, the DATEdatatype holds the time as well

注意trunc函数,即使你不显示它,DATE数据类型也会保存时间

Hereis a fiddle

是一个小提琴