MySQL Basics (vi) SELECT statement

Source: Internet
Author: User

Single-table query: &NBSP;&NBSP;&NBSP;&NBSP;SELECT&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[&NBSP;DISTINCT&NBSP;]         [SQL_CACHE | SQL_NO_CACHE]     &NBSP;&NBSP;&NBSP;&NBSP;SELECT_EXPR&NBSP;[,SELECT_EXPR&NBSP, ...]         [from table_references [ where where_ condition ]        [group by {col_name | expr  |}]  [HAVING where_condition] [ORDER BY [ASC | DESC]]   DISTINCT: Data deduplication sql_cache: Specify cache sql_no_cache: Specify cache     where clause: Specify conditions to implement filter filter conditions:      Arithmetic Arithmetic:+   -   *   /   %  >   <  >=  <=     logical operations: and: With operations   or: or operations    not: Non-arithmetic      character comparison:=  !=         list elements Comparison:in  (element 1, Element 2, Element 3,...)     is null: Empty     is not null: Non-empty      Like: fuzzy matching, can not use as much as possible     rlike: based on regular fuzzy matching, can not use as much as possible     GROUP  By clause: More specified conditions to group matching results, implementing "aggregation" operations          common functions:     SUM (condition) #求和             max (condition) #最大值      min (condition) #最小值     avg (condition) #平均值     count (condition) #统计记录数   & Nbsp; having: Example of filtering the results after Group by:    mysql> create database  MyDB, #创建测试数据库     mysql> USE mydb;    mysql>  create table test  (Id int), Name varchar (2), Qq int (Gender char) Create a test table     mysql> INSERT INTO Test values (1, ' Zhangshan ', 12345, ' F ');     #插入测试数据     mysql>  insert into test values (2, ' Lisi ', 123142, ' F ');    mysql>  Insert into test values (3, ' ZSF ', 124312, ' M ');    mysql> insert  Into test values (4, ' yyy ', 124312, ' F ');    mysql> insert into  Test values (5, ' Ytt ', 124312, ' M ');     single-table Query example:    mysql>  select * from test where id>2 and id<5; #查询ip大于2小于5的数据      mysql> SELECT * FROM test WHERE id>2 GROUP BY  gender; #对性别进行分组     mysql> select sum (ID),gender from test  group by gender; #对性别进行分组, and begged for the sum of their IDs     mysql> select * from  test group by gender having id>2; #对性别进行分组, display group          Multi-Table association queries with IDs greater than 2:     mysql> CREATE TABLE test2  (Emain varchar ($), Age int (10)); #创建测试环境     mysql> insert into test2 values (' [email protected] ' ,     mysql> insert into test2 values (' [email protected] ',     mysql> insert into test2 values (' [email protected] ', 20 );     mysql> select test.id,test2.age from test,test2 where  test.id>2 and test2.age>10;    test.id# the ID field of the first chapter table test2.age# Chapter II of the Age field test# first chapter table   table name test2# chapter II table   table name test.id>2 and test2.age# stitching displays the ID field of test and the age field of Test2. However, the ID field of test must be greater than 2 and the age field of test2 must be greater than 10    mysql> select * from test. Test2 where test.id>2 AND test2.age>10;     #拼接显示test, all fields of test2, However, the ID field of test must be greater than 2 and the age field of test2 must be greater than 10


This article is from the "Automated Operations" blog, please be sure to keep this source http://hongchen99.blog.51cto.com/12534281/1933300

MySQL Basics (vi) SELECT statement

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.