企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
> 当我们的查询添加越来越复杂的时候,简单的结构已经无法满足我们的需要,这时候我们就会需要一个完整的SQL语句构造,当然,我们考虑到了这些并做了一些调整 ```php //IN查询 $select = Db('user')->select([ 'field' => ['username', 'email'], //设定查询的字段 'where' => [ //定义查询的条件 'id' => array('in','1,6,8,9,10') ], 'limit' => '0, 10', //条数限制 'orderby' => 'username asc', //进行排序 ])->get(); //sql:SELECT `username`,`email` FROM `user` WHERE `id` IN (1,6,8,9,10) ORDER BY username asc LIMIT 0,10 //like查询 $select = Db('user')->select([ 'field' => ['username', 'email'], //设定查询的字段 'where' => [ //定义查询的条件 'username' => array('like','%张') ], 'limit' => '0, 10', //条数限制 'orderby' => 'username asc', //进行排序 ])->get(); //sql:SELECT `username`,`email` FROM `user` WHERE `username` LIKE '%张' ORDER BY username asc LIMIT 0,10 //自定义操作(获取所有周六注册的用户) $select = Db('user')->select([ 'field' => ['username', 'email'], //设定查询的字段 'where' => [ //定义查询的条件 '' => array('string',"FROM_UNIXTIME(add_time,'%w')=6") ], 'limit' => '0, 10', //条数限制 'orderby' => 'username asc', //进行排序 ])->get(); //sql:SELECT `username`,`email` FROM `user` WHERE FROM_UNIXTIME(add_time,'%w')=6 ORDER BY username asc LIMIT 0,10 ```