Summary of commonly used SQL statements in Mysql, and mysqlsql statements

Source: Internet
Author: User

Summary of commonly used SQL statements in Mysql, and mysqlsql statements


(1) Data Record Filtering:

SQL = "select * from data table where field name = Field Value order by field name [desc]" SQL = "select * from data table where field name like '% Field Value % 'order by field name [desc] "SQL =" select top10 * from data table where field name order by field name [desc] "SQL =" select * from data table where field name in ('value 1 ', 'value 2', 'value 3') "SQL =" select * from data table where field name between value 1 and value 2"

(2) update data records:

SQL = "update data table set field name = field value where condition expression" SQL = "update data table set field 1 = value 1, Field 2 = value 2 ...... Field n = value n where condition expression"

(3) Delete data records:

SQL = "delete from data table where condition expression" SQL = "delete from data table" (delete all records of data table)

(4) add data records:

<Span style = "font-size: 12px;"> <span style = "color: #000000;"> SQL = "insertinto data table (Field 1, Field 2, field 3 ...) Values (value 1, value 2, value 3 ...) "SQL =" insertinto target data table select * from source data table "(add records of source data table to target data table) </span>

(5) statistical functions of data records:

AVG (field name) obtains the average COUNT (* | field name) of a table column for statistics on the number of rows or the number of rows with values in a column for statistics MAX (field name) obtain the maximum value MIN (field name) in a table column to obtain the smallest value SUM (field name) in a table column to add the values in the data column and reference the above functions: SQL = "select sum (field name) as Alias from data table where condition expression" setrs = conn. excute (SQL) uses rs ("alias") to obtain the value of the system. Other functions are used in the same way.

(6) Create and delete data tables:

Create a data table: CREATETABLE data table name (Field 1 type 1 (length), Field 2 type 2 (length )......) Example: create table tab01 (namevarchar (50), datetimedefanow now () delete data TABLE: DROPTABLE data TABLE name (permanently delete a data TABLE)















Related Article

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.