SQL query key usage

一、between

It displays the value of a certain interval;

The SELECT  *  the FROM ` User ` the WHERE ID the BETWEEN  . 1  the AND  4 ; // show ID . 1 ~ data between 4

Two, in

Displaying a plurality of values ​​of an attribute;

The SELECT  *  the FROM ` User ` the WHERE id the IN ( 1 , 2 , 3 ); // id is displayed ( 1 , 2 , 3 ) data

三、like

Fuzzy query

The SELECT  *  the FROM ` the User ` the WHERE username the LIKE  ' % r ' ; // query the user name people r at the end of
 the SELECT  *  the FROM ` the User ` the WHERE username the LIKE  ' r% ' ; // query the user names of people at the beginning of r
 the SELECT  *  the FROM ` user ` the WHERE username the LIKE  ' % r% ' ; // query containing the user name who is r
 % wildcard, is understood to complement the missing portion

Four, ASC: ascending order, default value    DESC: descending

 

The SELECT  *  the FROM ` the User ` the ORDER  BY id ASC ; // query id ascending order based on
 the SELECT  *  the FROM ` the User ` the ORDER  BY id DESC ; // according to id DESC query
 the SELECT  *  the FROM ` the User ` the ORDER  BY id ASC , username; // according to ascending id, user name in alphabetical order, the weight of the former than the latter, the weight is higher than the user name id

 

Five, five aggregate function (max () min () avg () count () sum ())

 

 

SELECT  COUNT (IFNULL (id, 0 )) from Student; // query id field number, if null , use 0 instead of

六、GROUP BY

Query packet: the same data into a set.

The SELECT Sex, COUNT ( * ) the FROM ` the User ` the GROUP  BY Sex; // grouped by gender, and the number of inquiries each group

 七、having

 

 

 Eight, limit

LIMIT is limiting sense, so LIMIT role is to limit the number of query records.

 

LIMIT offset,length;

offset : start line number, from 0 starts counting, and if omitted, the default is 0

length : number of rows returned, counted from the number of offset

 

Guess you like

Origin www.cnblogs.com/hsRick/p/11644214.html