sql - 按月获取错误过滤记录SQL
问题描述
我有以下代码,我试图在其中查找 May 的记录并尝试按网站对它们进行分组。但是得到这个错误。知道为什么它说没有功能匹配吗?
SELECT
ad.site, SUM(e.clicks) AS totalclicks
FROM Extable e
INNER JOIN Ads ad ON e.ad_id = ad.ad_id
WHERE month(ad.Create_Time) = 5
Group by ad.site;
但我收到了这个错误
ERROR: function month(date) does not exist
LINE 4: WHERE month(ad.Create_Time) = 5
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 107
解决方案
这是 PostgreSQL 的日期/时间函数的文档。似乎您必须使用 EXTRACT() 或 DATE_PART()
date_part('hour', timestamp '2001-02-16 20:38:40')
extract(hour from timestamp '2001-02-16 20:38:40')
推荐阅读
- python-3.x - 用户数据脚本完成
- python - Python:从 AWS MediaConvert 中的最后一帧生成缩略图
- reactjs - 使用状态值响应获取
- sql - 在 has_many 关联中使用 Arel 计算 SQL AVG
- image - 需要解决方案来显示从后端到前端的图像
- java - 使用 List 比较和更改 Java 中 String 中的字符
- java - shedlock 通过 lockname 获取锁定状态
- r - 如何将数据从长格式转换为宽格式,以便将重复的行添加到末尾以在 R 中创建新列?
- android - 一段时间后,后台的 ExoPlayer 会丢失音频
- reactjs - 如何更改 React Router Link 组件中的状态?