如何使用 select 并将日期从 sequelize ORM 中的时间戳中提取到月份和年份?
how to use select and extract date into month and year from timestamp in sequelize ORM?
我在 sql 中有这个查询:
select to_char (created_at,'Mon') as month,
extract (year from created_at) as year,
id_activity as activity
from event
group by 1, 2, 3
我一开始尝试了一些简单的东西,比如这样来帮助我理解:
model.findAll({attributes: [[ sequelize.fn('extract(year)', sequelize.col('created_at')), 'data']] })
但它不起作用。
我正在使用 postgresDB
尝试如下 -
model.findAll({attributes: [[ sequelize.fn('YEAR', sequelize.col('created_at')), 'data']] })
希望对您有所帮助!
我在 sql 中有这个查询:
select to_char (created_at,'Mon') as month,
extract (year from created_at) as year,
id_activity as activity
from event
group by 1, 2, 3
我一开始尝试了一些简单的东西,比如这样来帮助我理解:
model.findAll({attributes: [[ sequelize.fn('extract(year)', sequelize.col('created_at')), 'data']] })
但它不起作用。
我正在使用 postgresDB
尝试如下 -
model.findAll({attributes: [[ sequelize.fn('YEAR', sequelize.col('created_at')), 'data']] })
希望对您有所帮助!