MYSQL Learning Series --DML statement (b)

introduction:

Data manipulation language (Data Manipulation Language, DML) is the SQL language, is responsible for operating data access instruction set to work on database objects to INSERT, UPDATE, DELETE three kinds of instruction as the core, representing the insert, update and delete, are developed to data-centric applications will certainly use the command

Hands-on

This is a continuation on an update written an article on: MYSQL Learning Series --DML statement (a)
The last time we were to say to insert, update, delete records, we have to introduce different play this query (related to some common functions)
4) query log
select 字段 from 表名
1> query does not duplicate records
here we use the mysql database that comes to demonstrate (information_schema)
MYSQL Learning Series --DML statement (b)
first, we need to use this database use information_schema;
queries after select COLUMN_NAME from COLUMNS;
MYSQL Learning Series --DML statement (b)
the general use of distinct, screening only one field! this is when a single table
select distinct COLUMN_NAME from COLUMNS;
MYSQL Learning Series --DML statement (b)
record or a lot, but you will find that duplicate still display will not be like before
2> query conditions
Note: Conditional field compare symbols:
! =, <,>,> =, <=, =, etc. Compare operators
can use across multiple conditions or and so on
where ground conditions behind
select * from 表名 where 条件
this demonstration I do not need you to play your own imagination
3> Sort and limit
syntax: order by field name sort
our first fight sequence data chaos, and then sorted
MYSQL Learning Series --DML statement (b)
ASC: from low to high, is the default
MYSQL Learning Series --DML statement (b)
desc: high in the end by a
MYSQL Learning Series --DML statement (b)
plurality of sort fields
MYSQL Learning Series --DML statement (b)
limits:
the rearmost limit plus the statement number 1, number 2 to the number of queries limits.
limit the number 1, number 2 numeral 1 denotes a recording turn taken from the first few (starting from 0), numeral 2 to take a few!
4> polymerization
①sum summing
select sum(字段名) from 表名;
MYSQL Learning Series --DML statement (b)
②count total number of records
select count(*|字段名) from 表名;
MYSQL Learning Series --DML statement (b)
③max maximum
select max(字段名) from 表名;
MYSQL Learning Series --DML statement (b)
④min minimum
select min(字段名) from 表名;
MYSQL Learning Series --DML statement (b)
⑤GROUP BY polymerization classification
select sum(number),Name from student group by Name;
MYSQL Learning Series --DML statement (b)
result of re-polymerization ⑥WITH ROLLUP classification summary
select sum(number) from student group by Name with rollup;
MYSQL Learning Series --DML statement (b)
⑦HAVING
NOTE: The difference is that where and HAVING, HAVING is the result of the polymerization conditions for filtering, and where it is recorded prior to polymerization filter, first filter the records should as far as possible!
MYSQL Learning Series --DML statement (b)
Research studies can own Baidu do not understand! ! ! Or give me a message

Guess you like

Origin blog.51cto.com/14113984/2428954