The use of MySQL's LIMIT, IN, etc.

1. LIMIT syntax

 

The first:

SELECT 

    column1,column2,...

FROM

    table

LIMIT offset , count;

 

The second:

SELECT 

    column1,column2,...

FROM

    table

LIMIT count;

 

2. IN syntax (or NOT IN)

 

SELECT 

    column1,column2,...

FROM

    table_name

WHERE 

 (expr|column_1) IN ('value1','value2',...);

 

 Note: The values ​​after IN must be separated by ",";

 Operators can also be used in the WHERE clause of other statements, such as INSERT, UPDATE, DELETE, etc.

 

 3. BETWEEN syntax (>= and <=)

 

 格式:expr [NOT] BETWEEN begin_expr AND end_expr;

 

* When working with date values, for best results, CAST type conversion should be used to explicitly convert the type of the column or expression to a date type;

 

 CAST (field name as converted type), where the type can be:

CHAR[(N)] character type 

DATE date type

DATETIME date and time type

DECIMAL  float型

SIGNED  int

TIME time type

 

4. LIKE ( NOT LIKE)用法

   Role: pattern matching

 

MySQL provides two wildcards using AND operation, "_" and percentage "%",

The percent (%) wildcard allows you to match any string of zero or more characters.

The underscore (_) wildcard can match any single character.

 

Note that the pattern is case-insensitive to similar operators, so the patterns of b% and B% produce the same result.

 

Use of escape character "ESCAPE", default is backslash "\".

eg : productCode LIKE '%\_20%';

 

A different escape character can be specified using the escape clause , e.g. $,

 eg: productCode LIKE '%$_20%' ESCAPE '$';  %$_20% 表示匹配包含“_20”字符串的任何字符串。

 

 5. ORDER BY 用法

 

 格式:SELECT column1, column2,...

FROM tbl

ORDER BY column1 [ASC|DESC], column2 [ASC|DESC...

 默认:ASC (升序)

 

 **自定义排序函数FIELD()

 格式:field(value,str1,str2,str3,str4)

       value与str1、str2、str3、str4比较,返回1、2、3、4,如遇到null或者不在列表中的数据则返回0。

 

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326262773&siteId=291194637