gpt4 book ai didi

postgresql - 如何在 PostgreSQL 中将 unix 时间戳列转换为日期格式?

转载 作者:行者123 更新时间:2023-11-29 14:13:46 25 4
gpt4 key购买 nike

我正在尝试从 unixtimestamp 列获取 yyyy-mm-dd 格式的结果,但进入的是 yyyy-mm-dd hh:mm:ss

我在 receive_time 列中的数据如下:

recieve_time

1557866863 |
1557866863 |
1557866863 |
1557866863 |
1557866864 |
1557866864 |
1557866864 |
1557866864 |

以下是我的查询:

SELECT
to_timestamp(recieve_time) as date, count(*)
FROM public.cdrs WHERE
usage_type='0800 Voice Incoming'
and to_timestamp(recieve_time) >='2019-05-01 00:00:00'
AND to_timestamp(recieve_time) <'2019-06-01 00:00:00'
AND main_bzd >0
group by to_timestamp(recieve_time)

得到这个:

date                 |count|

-------------------|-----|

2019-05-01 00:00:2 |1 |
2019-05-01 00:03:2 |1 |
2019-05-01 01:20:0 |1 |
2019-05-01 01:21:1 |1 |
2019-05-01 01:53:0 |1 |
2019-05-01 02:16:5 |1 |
2019-05-01 02:33:5 |1 |
2019-05-01 02:39:4 |1 |
2019-05-01 02:55:3 |1 |
2019-05-01 03:32:5 |1 |
2019-05-01 03:35:0 |1 |

我的要求如下:

date        |count|

------------|-----|

2019-05-01 |19 |
2019-05-02 |15 |
2019-05-03 |17 |

最佳答案

SELECT 列表和 GROUP BY 子句中将结果转换为 date:

CAST(to_timestamp(recieve_time) AS date)

关于postgresql - 如何在 PostgreSQL 中将 unix 时间戳列转换为日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56593435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com