首页 > 代码库 > thinkphp 区间查询 组合查询 复合查询 动态查询 SQL查询

thinkphp 区间查询 组合查询 复合查询 动态查询 SQL查询

区间查询 默认使用AND 在最后面元素加上OR  SELECT * FROM `weibo_user` WHERE ( `id` > 1 OR `id` < 3 )
$map[‘id‘]=array(
  array(‘gt‘,1),
  array(‘lt‘,3),
    ‘OR‘
);
组合查询  SELECT * FROM `weibo_user` WHERE `id` = 1 OR ( username = "bnbbs" AND email like "%bnbb%" )
$map[‘id‘]=array(‘eq‘,1);
$map[‘_string‘]=‘username = "bnbbs" AND email like "%bnbb%"‘;
$map[‘_logic‘]="OR";
请求字符串查询
$map[‘id‘]=array(‘eq‘,1);
$map[‘_query‘]=‘username=bnbbs&_logic=OR‘;
$map[‘_logic‘]=‘OR‘;
复合查询  SELECT * FROM `weibo_user` WHERE `id` = 1 OR ( `id` = 2 )
$map[‘id‘]=array(‘eq‘,1);
$where[‘id‘]=array(‘eq‘,2);
$map[‘_complex‘]=$where;
$map[‘_logic‘]=‘OR‘;
统计查询 count() SELECT COUNT(*) AS tp_count FROM `weibo_user` LIMIT 1
最大查询 max(id) SELECT MAX(id) AS tp_max FROM `weibo_user` LIMIT 1
最小查询 min(id) SELECT MIN(id) AS tp_min FROM `weibo_user` LIMIT 1
平均值查询 avg(id)  SELECT AVG(id) AS tp_avg FROM `weibo_user` LIMIT 1
求和查询 sum(id) SELECT SUM(id) AS tp_sum FROM `weibo_user` LIMIT 1
动态查询
getByField(value) SELECT * FROM `weibo_user` WHERE `id` = 1 LIMIT 1
getByField(value) SELECT * FROM `weibo_user` WHERE `username` = ‘bnbbs‘ LIMIT 1
getFieldByField(value) SELECT `id` FROM `weibo_user` WHERE `username` = ‘bnbbs‘ LIMIT 1
SQL查询 query($sql)只读 execute($sql)只写

var_dump($user->query(‘select * from weibo_user‘));


thinkphp 区间查询 组合查询 复合查询 动态查询 SQL查询