Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 日期记忆功能的使用_Sorting_Date - Fatal编程技术网

Sorting 日期记忆功能的使用

Sorting 日期记忆功能的使用,sorting,date,Sorting,Date,DATE_TRUNC功能是否允许您解决过去30天内每天事件天数的计算问题?是-假设您使用Postgres-您可以使用该功能提取日期部分,然后对每个特定日期的事件进行分组和计数 在下面的示例中,我有一个带有时间戳列的表tb\u registration,我使用date\u TRUNC函数按天、月、年分组。在本例中,我还对date列应用了特定天数的过滤器 select date_part('day', DATE_TRUNC('day', date)) "day", date_part('mon

DATE_TRUNC功能是否允许您解决过去30天内每天事件天数的计算问题?

是-假设您使用Postgres-您可以使用该功能提取日期部分,然后对每个特定日期的事件进行分组和计数

在下面的示例中,我有一个带有时间戳列的表
tb\u registration
,我使用
date\u TRUNC
函数按天、月、年分组。在本例中,我还对
date
列应用了特定天数的过滤器

select date_part('day', DATE_TRUNC('day', date)) "day", 
  date_part('month', DATE_TRUNC('month', date)) "month", 
  date_part('year', DATE_TRUNC('year', date)), count(*) "year"
    from tb_registration where date > NOW() - INTERVAL '600 days'
      group by DATE_TRUNC('day', date), 
        DATE_TRUNC('month', date), 
        DATE_TRUNC('year', date) order by 3 desc, 2 desc, 1 desc
此查询生成以下结果:

14;4;2017;1
11;4;2017;90
10;4;2017;99
9;4;2017;60
8;4;2017;66
7;4;2017;83
6;4;2017;87
5;4;2017;76
4;4;2017;91
3;4;2017;110
2;4;2017;52
1;4;2017;46
31;3;2017;66
其中列为:

  • 一天
  • 计数

  • 嗨,欢迎来到stack overflow。有关如何提问和相应更新问题的更多详细信息,请参阅链接。欢迎使用stackoverflow。只有一个问题:你是否使用Postgres作为你的数据库?