MySQL various queries

Source: Internet
Author: User

1. Simple query

SELECT * from info;

Select Code as ' Code ', name as ' name ' from info;

2. Conditional query

SELECT * from car where code = ' c002 ';

SELECT * FROM car where brand = ' b001 ' and power = 130; #或用or

3. Fuzzy query

SELECT * from car where name like '% Audi% '; % represents any number of characters including 0 _ for one character

4. Sort queries

SELECT * FROM Car order by brand, Powers Desc; ASC Ascending default can not write

5. Scope Query

SELECT * from car where price between and 60;

6. Discrete query

SELECT * from car where code in (' Coo1 ', ' c003 ', ' c005 ', ' c007 ');

SELECT * from car where code not in (' coo1 ', ' c003 ', ' c005 ', ' c007 ');

7. Statistical queries (aggregation functions)

Select count (code) from car; Query data Bar count (*) can also be written so that performance is low

Select SUM (price) from car; Sum

Select Max (code) from car; Biggest

Select min (brand) from car; Minimum

Select AVG (price) from car; Average

8. Paging Query

SELECT * from Car limit (n-1) *5,5 #第n页, showing five data per page

9. Go to re-query

Select distinct Brand from Car

10. Group queries

Select Brand,count (*), brand from Car GROUP by Brand #把brand列的相同值组合起来, and this data operates on the column or other columns such as averaging
Select brand from Car GROUP by Brand have Count (*) >3 #分组之后根据条件查询使用having do not use where

MySQL various queries

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.