thinkphp 区间查询 组合查询 复合查询 动态查询 SQL查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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查询的主要内容,如果未能解决你的问题,请参考以下文章
Thinkphp 查询条件 and 和 or同时使用即复合查询