Home > Article > Backend Development > The format of expression query in thinkPHP SQL statement
For those queries that need to achieve fuzzy judgment, such as SQL queries such as greater than, equal to, less than, etc., you can use the expression query method.
Query expression format: $map['field name'] = array('expression','query condition');
PS: Expressions are not case-sensitive.
Example:
//EQ: equal to (=)
$map['id'] = array('eq', 1); //where is id=1
//NEQ: not equal to ()
$ map['id'] = array('neq', 1); //where is id1
//GT: greater than (>)
$map['id'] = array('gt', 1); //where is id>1
//EGT: greater than or equal to (>=)
$map['id'] = array('egt', 1); //where is id>=1
//LT: less than ($map['id'] = array('lt', 1); //where is id//ELT: less than or equal to ($map['id'] = array( 'elt', 1); //where is id//[NOT]LIKE: fuzzy query
$map['user'] = array('like', '%小%'); //where For like %小%
//[NOT]LIKE: Fuzzy query
$map['user'] = array('notlike', '%小%'); //where for not like %小%
//[ NOT]LIKE: Array method of fuzzy query
$map['user'] = array('like', array('%小%', '% wax%'), 'AND');
//Generated SQL
SELECT * FROM `think_user` WHERE ( (`user` LIKE '%小%' AND `user`
LIKE '%wax%') )
//[NOT] BETWEEN: interval query
$map['id'] = array('between','1,3');
//where is `id` BETWEEN '1' AND '2'
//Same as above and equivalent
$map['id'] = array('between' ,array('1','3'));
//[NOT] BETWEEN: interval query
$map['id'] = array('not between','1,3');
//where For `id` NOT BETWEEN '1' AND '2'
//[NOT] IN: interval query
$map['id'] = array('in','1,2,4');
// where is `id` IN ('1','2','4')
//[NOT] IN: interval query
$map['id'] = array('not in','1,2, 4');
//where is `id` NOT IN ('1','2','4')
//EXP: Custom
$map['id'] = array('exp',' in (1,2,4)');
//where is `id` NOT IN ('1','2','4')
PS: Use exp customization to directly write the where statement in the second parameter Just
//EXP: Customize the OR statement
$map['id'] = array('exp', '=1');
$map['user'] = array('exp', '= "Crayon Shin-chan"');
$map['_logic'] = 'OR';
//WHERE is ( (`id` =1) ) OR ( (`user` =" Crayon Shin-chan") )