查询今天尚未完成调查的用户并收到错误

乔·斯莱克

我有一个正在使用的功能,我需要PostgreSQL db返回今天尚未完成调查的所有用户。

select distinct *
from users 
left join survey_results
on users.user_id = survey_results.user_id
where customer_id = '9000'
and survey_results.created_at < (DATE_PART('year', survey_results.created_at) = (SELECT EXTRACT(YEAR FROM CURRENT_TIMESTAMP))
                                  AND DATE_PART('month', survey_results.created_at) = (SELECT EXTRACT(MONTH FROM CURRENT_TIMESTAMP)) 
                                  AND DATE_PART('day', survey_results.created_at) = (SELECT EXTRACT(DAY FROM CURRENT_TIMESTAMP)))

我正在使用左联接联接到我的调查结果表上,并按customer_id进行过滤,并在survey_results.created <今天进行了过滤,但我正在使用日期部分并提取以获取日期。如果有更好的方法可以做到这一点,那就是我所拥有的。

我在运行查询而不是结果时收到此输出。

ERROR:  operator does not exist: timestamp with time zone < boolean
LINE 6: and survey_results.created_at < (DATE_PART('year', survey_re...
                                      ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
SQL state: 42883
Character: 155
Ankit bajpai

与其使用datepart,不如将其与current_date进行比较-

select distinct *
from users 
left join survey_results
on users.user_id = survey_results.user_id
where customer_id = '9000'
and survey_results.created_at < CURRENT_DATE

如果您的survey_results.created_at列为时间戳,请使用date函数将其转换为日期,然后将其与current_date进行比较-

select distinct *
from users 
left join survey_results
on users.user_id = survey_results.user_id
where customer_id = '9000'
and DATE(survey_results.created_at) < CURRENT_DATE

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

SVN错误“先前的操作尚未完成”

来自分类Dev

在Azure DevOps中,如何查询尚未完成并延续到当前sprint迭代的用户故事?

来自分类Dev

dispatch_async尚未完成

来自分类Dev

“调试正在停止”,但尚未完成

来自分类Dev

Foundation 5构建尚未完成

来自分类Dev

JEST with Express尚未完成

来自分类Dev

ExecuteReader:连接属性尚未完成

来自分类Dev

Netbeans尚未完成创建项目

来自分类Dev

SQL查询未完成

来自分类Dev

查询表在尚未完成时打开 Excel 文件 (VB.NET)

来自分类Dev

调用didFinishNavigation时,WKWebView尚未完成加载-WKWebView中的错误?

来自分类Dev

Color-Thief Node插件错误:“给定的图像尚未完成加载”

来自分类Dev

将pdf打印到onenote尚未完成,没有错误显示

来自分类Dev

Ubuntu 18.04“启动尚未完成。请稍后再试。” 错误

来自分类Dev

如果尚未完成动画,如何立即完成动画?

来自分类Dev

当Mouseenter尚未完成时,Mouseleave不会触发

来自分类Dev

jQuery animate()尚未完成动画制作

来自分类Dev

安装12.04后PC尚未完成重启过程

来自分类Dev

URLConnection尚未完成获取InputStream的操作

来自分类Dev

System.InvalidOperationException:异步操作尚未完成

来自分类Dev

如果功能尚未完成,请使用超时返回

来自分类Dev

从订阅获得未定义的属性尚未完成

来自分类Dev

安装12.04后PC尚未完成重启过程

来自分类Dev

恢复购买的应用程序尚未完成

来自分类Dev

引导尚未完成。请稍后再试

来自分类Dev

引导尚未完成。请稍后再试

来自分类Dev

Ode23尚未完成执行

来自分类Dev

请求尚未完成,mongoDB 和 Express 出错

来自分类Dev

java.lang.IllegalStateException:任务尚未完成

Related 相关文章

热门标签

归档