如何使用别名选择列

Tim*_*ney 11 javascript sql sequelize.js

我如何执行这样的SQL查询?

SELECT column_name AS alias_name FROM table_name;

示例:我希望将"first"列选为"firstname"

Table.findAll({
      attributes: [id,"first"]
    })
    .then(function(posts) {
        res.json(posts);
    })
Run Code Online (Sandbox Code Playgroud)

Jan*_*ier 33

Table.findAll({
  attributes: ['id', ['first', 'firstName']] //id, first AS firstName
})
.then(function(posts) {
  res.json(posts);
});
Run Code Online (Sandbox Code Playgroud)

  • 它可以工作,但是当在连接查询中使用时,它会将表名附加到给定的别名.有没有办法删除表名? (9认同)