egg-mysql中select如何联表查询重命名字段
发布于 6 年前 作者 yuquanH 3420 次浏览 来自 问答

const results = await this.app.mysql.select(‘posts’, { // 搜索 post 表 where: { status: ‘draft’, author: [‘author1’, ‘author2’] }, // WHERE 条件 columns: [‘author’, ‘title’], // 要查询的表字段 orders: [[‘created_at’,‘desc’], [‘id’,‘desc’]], // 排序方式 limit: 10, // 返回数据量 offset: 0, // 数据偏移量 });

=> SELECT author, title FROM posts WHERE status = ‘draft’ AND author IN(‘author1’,‘author2’) ORDER BY created_at DESC, id DESC LIMIT 0, 10; 在上面的table使用数组时可以查询两个表,因为列名一样,columns想重命名,不知怎么做

回到顶部