Database Simple Query

Source: Internet
Author: User

1, the simplest query:

SELECT * from Car;

2, Query Development column:

Select name oil,powers from car;

3, change the name of the listed names:

Select name as ' car name ', oil as ' fuel consumption ', powers as ' power ' from car;

4. Search by Condition:

Select Name,oil,powers from car where oil = 8.7;

5, multi-criteria query:

Select Name,oil,powers from car where oil = 8.7 or powers = 160;
Select Name,oil,powers from car where oil = 8.7 and powers = 160;

6. Scope Query:

SELECT * from car where price>=40 and price <=60;
SELECT * from car where price between and 60;

7. Discrete query:

SELECT * from car where powers = Powers = or powers = 170;
SELECT * from car where powers in (130,150,170);
SELECT * from car where powers not in (130,150,170);

8, Fuzzy query:

SELECT * from car where name like '% BMW% ';
SELECT * from car where name like ' _ BMW% ';

9. Sort query: ASC Ascending desc descending order BY

SELECT * FROM car order by oil ASC;
SELECT * FROM Car ORDER by brand Asc,price desc;

10, to repeat the query: distinct

Select distinct brand from car;

11, paging query:

SELECT * FROM Car limit 5, 5;
N;m = 5;
Limit (n-1) *m,m; Added

12. Aggregate function Query:

Count (column name) sum (column name) AVG (column name) max (column name) min ()
Select COUNT (*) from car;
Select SUM (price) from car;
Select AVG (price) from car;
Select Max (price) from car;
Select min (price) from car;

 

Database 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.