【发布时间】:2019-09-04 09:34:33
【问题描述】:
我想要逗号分隔的唯一 from_date 在一行中。
所以我在TO_TIMESTAMP() 中使用distinct() 函数,但出现错误。
SELECT string_agg(TO_CHAR(TO_TIMESTAMP(distinct(from_date) / 1000), 'DD-MM-YYYY'), ',')
FROM trn_day_bookkeeping_income_expense
GROUP BY from_date,enterprise_id having enterprise_id = 5134650;
我想要这样的输出:
01-10-2017,01-11-2017,01-12-2017
但我收到如下错误:
ERROR: DISTINCT specified, but to_timestamp is not an aggregate function LINE 1: SELECT string_agg(TO_CHAR(TO_TIMESTAMP(distinct(from_date) /...**
【问题讨论】:
-
from_date是什么数据类型,为什么要在上面使用to_timestamp()?为什么不将时间戳值存储在timestamp列中? -
数据类型为 bigint。 to_timestamp() 用于将 bigint 转换为日期格式
-
为什么不将时间戳值存储在
timestamp列中?那么你就不需要每次想要一个正确的时间戳时都调用to_timestamp() -
请建议我如何将时间戳值存储在时间戳中
-
使用数据类型
timestamp
标签: sql postgresql timestamp aggregate distinct