快捷查询
where('id&age','>',0);
where('id|age','>',0);
闭包查询
$result = Db::name('data')
->select(function($query){$query->where('name','like','%think%')
->where('id','in','1,2,3')->limit(10);
});
$result = Db::name('data')
->select(function($query){$query->where('name','like','%think%')
->where('id',' between',[1,3])->limit(10);
});
获取列数据,并且以id为索引
$list = Db::name('data')
->where('status',1)
->column('name','id');
聚合查询
Db::name('data')
->where('id','>',1)
->count();
Db::name('data')
->where('id','>',1)
->max('age');
字符串查询
$result = Db::table('user')
->where('id>:id and name is not null',['id'=>10])
->select();
日期时间查询
查询大于某日的数据
$result = Db::table('user')
->whereTime('create_time','>','2017-01-01')
->select();
查询本周的数据
$result = Db::table('user')
->whereTime('create_time','week')
->select();
查询最近两天添加的数据
$result = Db::table('user')
->whereTime('create_time','-2 days')
->select();
查询一个时间范围的数据
$result = Db::table('user')
->whereTime('create_time','between',['2017-1-1','2017-1-10'])
->select();
查询上周的数据
$result = Db::table('user')
->whereTime('create_time','last week')
->select();
参考:https://blog.csdn.net/haibo0668/article/details/78203170/
参考:https://www.cnblogs.com/nnhgd/p/9778251.html