1
select SPARE_PART_ID amont_id,sum(amount) monthAmount
from pmms.SPARE_PART_TRANS_INFO
where trans_type='2'
and CAST(created_dt AS date) between '2016-09-19' and '2016-09-27'
group by SPARE_PART_ID,DATEADD(month, DATEDIFF(month, 0, CAST(created_dt AS date)), 0)
在这个查询中DATEADD和DATEDIFF函数不工作,因为它说的月份不存在。有人可以帮我写postgres中的这个SQL查询
帮助赞赏。
**错误**错误:列 “月” 不存在 LINE 2:SPARE_PART_ID,DATEADD(月,DAT ... ^ ...”和 '2016年9月27日' 组** ********错误********** 错误:列“月”不存在 SQL状态:42703 字符:207 –
在这里您可以看到MS SQL和Postgres之间的变化:http://www.sqlines.com/postgresql/how-to/dateadd http://www.sqlines.com/postgresql/how-to/datediff – McNets
其中[在Postgres手册](http:// www。 postgresql.org/docs/current/static/index.html)你找到了'dateadd()'或'datediff()' –