Mysql query statement of where

Simple query
select * from table_name; all the data in the lookup table, if the amount of data is small, only a few dozen can check this, so it is not advisable to use.
select name, id from table_name; field within a lookup table name, id display only two data fields.
select id, name, job as name_job from table_name; as usage, the job setting field alias name_job. Just modify the display data, the table data should not.

The precise conditions query
select name from table_name where name = ' aaa'; query name is information aaa.
select name from table_name where sal> 3500 ; query wage greater than 3500 names. <(Less than) <> /! = (Not equal)

Fuzzy query conditions like
Show the Variables like 'Character%'; mysql query character set '%' match behind partially omitted
select * from table_name where name like 'Yang%'; student information query folks.

Range queries BETWEEN and
SELECT from table_name WHERE SAL BETWEEN 1000 and 5000; 1000 to 5000 wage query; information
SELECT
from table_name WHERE datetime BETWEEN '2015-01-01' and '2018-01-01'; date content between the query .

Discrete inquiries in ()
the SELECT * from table_name the WHERE name in ( 'Joe Smith', 'John Doe', 'king'); lookup table contains information on these three individuals, several queries to several display.

Clear duplicate values DISTINCT ()
the SELECT DISTINCT (job) from table_name; inquire how many job positions. One kind of positions on the show once.

Statistics Query COUNT (), SUM (), max (), AVG (), min ()
the SELECT COUNT ( ) from table_name; how many there are in the data tables.
select sum (sal) from table_name; sal summing the data field.
max () queries the maximum
SELECT
from table_name WHERE SAL = (SELECT max (SAL) from table_name); the maximum salary personnel information query.
AVG () averaging
min () Min

Guess you like

Origin blog.51cto.com/8922100/2480557