MySQL Simple query

Source: Internet
Author: User

1. General Enquiry

SELECT * from info; #查询所有内容

Select Code,name from Info #查询某几列

2. Conditional query

SELECT * from Info where code= ' P001 ' #条件查询

SELECT * from Info where Nation = ' n001 ' and sex= true #条件之间并的关系
SELECT * from Info where Nation = ' n001 ' and sex = ' 1 '

SELECT * from Info where Sex = False or Nation = ' n002 ' #条件之间或者的关系


3. Fuzzy query (search keywords)


SELECT * from chinastates where areaname like '% ' #查询以中开头的

SELECT * from chinastates where areaname like '% City% ' #查询包含 City info

SELECT * from chinastates where areaname like ' _ City% ' #查询城 data appearing in the second position

4. Sorting

SELECT * from Car ORDER BY Code DESC #desc降序 ASC Ascending

SELECT * from Car ORDER by Brand

SELECT * from Car ORDER by Brand,powers #按照两个列排序

5. Statistical queries (aggregation functions)

Select COUNT (*) from Car #查询总条数 * represents all columns

Select COUNT (Code) from Car #查询某一列

The maximum value of the Select Max from Car #查询 the price joins

Select min (Price) from Car #查询最小值

Select AVG (price) from Car #查询平均值

Select SUM (Price) from Car #查询总和

6. Group queries
Select Brand,count (*) from Car GROUP by Brand #根据系列 Group (group) view the number of data bars per group

Select Code,brand,count (*) from Car GROUP by Brand #根据Brand分组查看Code, brand data bar

SELECT * FROM Car GROUP by Brand have Count (*) >2 #查询分组之后数据条数大于2的, group cannot add where

7. Paging Query
SELECT * from Car limit 0,5 #查询跳过0条 Take 5 strips

SELECT * from Car limit 5,5 #跳过几条取几条数据

MySQL Simple query

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.