【发布时间】:2024-01-10 22:13:01
【问题描述】:
在此查询中,case 中的“每日”将被一个变量替换。我无法使这个查询工作。我希望根据变量的值将日期列设置为一天、一个月或一周或一年。但它给了我各种错误..
- CASE 类型日期和双精度无法匹配
- “as”附近的语法错误
我做错了什么?
select
case 'Daily'
when 'Daily' then DATE(to_timestamp(e.startts)) as "Date",
when 'Weekly' then DATE_PART('week',to_timestamp(e.startts)) as "Date",
when 'Monthly' then to_char(to_timestamp(e.startts), 'mm/yyyy') as "Date",
when 'Yearly' then to_char(to_timestamp(e.startts), 'yyyy') as "Date",
end
sum(e.checked)
from entries e
WHERE
e.startts >= date_part('epoch', '2020-10-01T15:01:50.859Z'::timestamp)::int8
and e.stopts < date_part('epoch', '2021-11-08T15:01:50.859Z'::timestamp)::int8
group by "Date"
【问题讨论】:
标签: postgresql case