MySQL Database Basics Learning Notes (iii)

Source: Internet
Author: User

SQL Statement Combat-DML Statement (emphasis)

Select: SELECT * FROM table1 where range

Insert: INSERT INTO table1(filed1,filed2)values (filed1,filed2)

Explanation:filed1,filed2 field name ; filed1,filed2 field value

Delete: Delete from table1 where range

Update: Update table1 set field1=value1 where range

Find: SELECT * from Table1where filed1 like '%value1%'

Explanation: Finding a fuzzy match that contains value1

If the search begins with value1 , then use 'value1%';

If the search ends with value1 : Then use '%value1';

Sort by: SELECT * FROM table1 ORDER by Filed1,filed2[desc]

Explanation: [DESC] Flashback [ASC] Positive Order

Total: Select COUNT (*) as TotalCount from table1

sum: select SUM (field1) as Sumvalue from table1

Average: Select AVG (field1) as Avgvalue from table1

Maximum: select Max (field1) as MaxValue from table1

Minimum: Select min (field1) as MinValue from table1


Practical Practice:

1) Insert

Insert four data to persion_info:

statement: (person_id is self-growing, so do not write)

Insert into Person_info (name,country,salary)

VALUES (' Xiao Zhao ', ' China ', 1200.01),

(' Penny ', ' Shanghai ', 1600.32),

(' Xiao Sun ', ' Guangzhou ', 2000.40),

(' Xiao Li ', ' Zhuhai ', 1670.88);

Execution Result:


2) Update:

If you want to put Xiao Zhao's The Country field is changed to Beijing, then the statement is executed:

Update Person_info Set country = ' Beijing ' WHERE name = ' xiao Zhao ';

The following results are performed:


3) sort

the name order by ordering

statement:SELECT * from Person_info order by name Desc;

Operation Result:


4) Find

find fuzzy match data containing "Zhao", statement ""

Select * from Person_info where name is like ' % Zhao % ' ;

Operation Result:

5) Total

Find The total number of data in Person_info table

statement: Select Count (*) as totalcount from Person_info;

Execution Result:


The visible result is 4, and the field name is totalcount.

6) sum

statement:Select sum (Salary) as Sumvalue from Person_info;

Execution Result:










MySQL Database Basics Learning Notes (iii)

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.