zoukankan      html  css  js  c++  java
  • tp5中的一些where操作

    快捷查询

    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();
  • 相关阅读:
    poj 3621(最优比率环)
    bzoj 1497(最大权闭合子图)
    Dinic(模板 再错是不可能的 这辈子都不可能了)
    BZOJ 2038
    zoj 3822(概率dp)
    poj 3683(2-sat+拓扑排序)
    poj 2186(tarjan+缩点)
    hdu 5782(kmp+hash)
    hdu 6035(树形dp)
    Python爬取房屋租售信息
  • 原文地址:https://www.cnblogs.com/nnhgd/p/9778251.html
Copyright © 2011-2022 走看看