egg icon indicating copy to clipboard operation
egg copied to clipboard

mysql如何模糊查询

Open tardis9527 opened this issue 9 years ago • 2 comments

教程里看到下面这个mysql 的使用方式,不过想补充稳一点,如何配置 like 的模糊查询

条件查询和结果定制 const results = yield 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;

tardis9527 avatar May 18 '17 09:05 tardis9527

自己写 SQL 查询就可以了。

dead-horse avatar May 19 '17 09:05 dead-horse

经常会有like的需求 增加一个like字段不行么

yuu2lee4 avatar Jan 01 '19 08:01 yuu2lee4