我正在尝试以 'YYYY-MM-DD' 格式转换列 unixtime 数据,但没有得到它。我的列的数据类型是数字。
我尝试了以下查询,但出现错误:
select to_timestamp(starttime,'YYYY-MM-DD') , count(*) from cdrs_052019 group by 1
查询执行失败
原因:SQL 错误 [42883]:错误:函数 to_timestamp(numeric, unknown) 不存在 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。职位:8
|starttime |endtime |duration|duration_min|
|----------|----------|--------|------------|
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694960 |0 | |
|155694960 |155694959 |1 | |
需要以下格式的结果:
starttime | count(*)
2019-05-01 56666
2019-05-02 77777
2019-05-03 69495
2019-05-04 4447
好的,您可以通过 将时间戳转换为日期类型::date
,示例如下:
postgres=# select to_timestamp(1503504000);
to_timestamp
------------------------
2017-08-24 00:00:00+08
(1 row)
postgres=# select to_timestamp(1503504000)::date;
to_timestamp
--------------
2017-08-24
(1 row)
您想要的最终 SQL:
select
to_timestamp(starttime)::date as the_date,
count(1)
from
cdrs_052019
group by
to_timestamp(starttime)::date
order by
the_date
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句