在内部联接中选择“最大值”

时间:2019-12-02 08:52:52

标签: node.js sequelize.js max inner-join

如何将此sql查询转换为Sequelize?

从站中选择a.id,a.name,max(b.sentAt)作为sendAt作为内部连接Monitoring_data_info作为a.id = b.stationId组上的b,按a.id,a.name < / strong>

结果是:enter image description here

我尝试了以下代码,但无法运行:

static findStationInfo (){
    return this.findAll({
      attributes : ['id', 'name', [Sequelize.fn('max', Sequelize.col('sentAt')), 'sentAt']],
      include: [{model: MonitoringDataInfo, attributes : [], required: true}],
      group: ['Station.id', 'Station.name']
    })
  }

0 个答案:

没有答案