PostgreSQL 中是否有与此 T-SQL 命令等效的命令?
SELECT COUNT(*)
FROM [dbo].[LayerTable]
where layerType=3
and created >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp))),0)
我找到了 date_part() 和 extract function() 但不起作用。
最佳答案
看起来这只是从 current_timestamp 中减去 6 个月,所以等价的是:
SELECT COUNT(*)
FROM dbo.layer_table
where layer_type=3
and created >= current_timestamp - interval '6 months';
如果您想要月初(而不是与“今天”“同一天”)作为结果,请使用:
created >= date_trunc('month', current_timestamp - interval '6 months')
关于sql - PostgreSQL 中两个日期之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53257345/