MySQL Simple Statement (2)

Source: Internet
Author: User

Creating database: Create library name;

Creating Table: Create table table name (column name data type (length) primary key, column name data type is empty ... );

Note: Do not add commas to the last column. Multiple statements are executed together, plus semicolons. Code symbol half-width.

CREATE TABLE Keyword: primary key primary

Non-empty NOT NULL

Self-growing column auto_increment

Foreign key relationship foreign key (column name) references table name (column name)

Add data: INSERT into table name values (', ', ', ') in parentheses are the same as the number of columns in the table

Insert into table name (column name, column name) VALUES (",") to add the specified column

Modify data: Update table name set column = new value where condition;

Delete data: Delete from table where+ condition;

Normal query: Select (Result display column) from table name

Conditional query: Select (Result display column) from table name where condition

Sort query: Selert (Results display column) from table name order BY column name (ASC/DESC), column name (ASC/DESC) ...

Aggregate function: SELECT COUNT (*) from table name #取个数

Select SUM (column name) from table name #查询列的和

Select AVG (column name) from table name #查询平均值

Select Max (column name) from table name #查询最大值

Select min (column name) from table name #查询最小值

Paged Query: SELECT * FROM table name limit n,m #跳过n条取m条

Group query: Select Column name from table name Group By column name #简单的分组查询

Select brand from Car GROUP by Brand has count (*) >2 #查询系列里面车的数量大于2的系列

Go to re-query: SELECT DISTINCT column name from table name

Modify Column Name: Select column name as ' new column name ' from table name

Fuzzy query: SELECT * FROM table name where name like ' _ Audi% ' # any combination % represents an infinite character _ represents any combination of characters

Discrete query: SELECT * FROM table name where column name In/not in (', ' ', ')  

greater than all data: SELECT * from table name where column name >all (50,40,30)

MySQL Simple Statement (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.