thinkphp the format of an expression query in an SQL statement

Source: Internet
Author: User
For queries that want to implement fuzzy judgments, such as SQL queries that are greater than, equal to, or less than, you can use an expression query method.
Query expression format: $map [' field name '] = Array (' expression ', ' query condition ');

PS: The expression is case-insensitive.

Example:
EQ: Equals (=)
$map [' id '] = array (' eq ', 1); Where is id=1
NEQ: Not equal to (<>)
$map [' id '] = array (' NEQ ', 1); Where is id<>1
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<1
ELT: Less than or equal (<=)
$map [' id '] = array (' ELT ', 1); Where is Id<=1
[Not]like: Fuzzy query
$map [' user '] = array (' Like ', '% small% '); Where is like% small%
[Not]like: Fuzzy query
$map [' user '] = array (' notlike ', '% small% '); Where is not like% small%
[Not]like: Array mode for fuzzy queries
$map [' user '] = array (' Like ', array ('% small% ', '% wax% '), ' and ');
The generated SQL
SELECT * from ' think_user ' WHERE (' user ' like '% small ' and ' user '
Like '% wax% '))
[NOT] Between: Interval query
$map [' id '] = array (' Between ', ' 1,3 ');
Where is ' id ' between ' 1 ' and ' 2 '
Ibid equivalent
$map [' id '] = array (' Between ', Array (' 1 ', ' 3 '));
[NOT] Between: Interval query
$map [' id '] = array (' Not between ', ' 1,3 ');
Where is ' 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 ', ' 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 custom to write a where statement directly in the second parameter
EXP: Custom Add or statement
$map [' id '] = Array (' exp ', ' = 1 ');
$map [' user '] = Array (' exp ', ' = ' crayon small new ');
$map [' _logic '] = ' OR ';
WHERE is ((' id ' =1)) OR ((' user ' = "crayon Small New"))

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.