Mysql database command base

To delete a table:

drop table if exists 表名;

Insert rows in the table:

Insert into 表名 values(, , ,)

Create a table:

Create table 表名(

Id int (10) primary key auto_increment, // auto_increment increment means

Name varchar(10),

Age int unsigned,

Height decimal(5,2))

 

Delete Row:

Delete from 表名 where ……

 

Tinyint type occupies one byte, 8 'bit, in the range of 0-255,

Int four bytes for Type

 

Lookup table:

Select * from table name lookup table in all fields

Select name, age from table name query from the table name, age row

Select name as an alias name queries from table columns from the table, and column for the name from an alias

Select distinct sex from table queries sex columns from the table, leaving only the non-repetition, distinct: do not repeat

Select name from the table name where ...... lookup table according to the conditions in the name field

Select * from table where name like "Sun%" fuzzy query, all fields in the lookup table name as X or Sun Sun Sun XX or XXX, etc.

Select * from table where name like "Sun _ _" Find the names of all the fields name is Sun XX

Select * from table where name in ( "Pharaoh", "Li", "Monkey") to find the name of the Pharaoh, talk of the town, Monkey fields

Select * from table where age between 18 and 20 to find all fields between the age of 18-20 years old

Select * from table where age is null query does not age all fields

 

Sort by:

Select * from table name order by age sorted according to age, the default ascending (asc)

Select * from table name order by age desc sorted according to age, in descending order

 

Aggregation function:

Select count (*) from table name query number of rows

Select count (age) from table name query number of rows age column does not contain null

Select agv (age) from the average age of a query table name

Select sex, count (*) from table group by sex having sex = 'male' sex between men and women, respectively, the number of queries people, group by a group, gender group, having similar where, followed by conditions

Select * from table limit startNum, count, such as select * from table limit 0,3 starting from the first row in the table, three lines of inquiry.

 

Equivalent connection:

Select * from Table 1, Table 1. Table 2 where the column name column name = Table 2

 

En:

Select * from Table 1 inner join Table 2 on Table 1. Table 2. Field field =

 

Select * from Table 1 join Table 2 on the connection conditions,

                            Table 2 join Table 3 on the connection condition;

                            (Later also with where + condition)

 

Left join, join replaced by left join

Right connection, join into right join

Guess you like

Origin www.cnblogs.com/6J2B2/p/12028512.html