Database---General query

Source: Internet
Author: User

General Query:
One: Query all data
SELECT * FROM Info check all data
Select Code,name from Info for specific columns

Second: According to the conditions to check
SELECT * from Info where code= ' p001 ' a conditional query
SELECT * from Info where code= ' p001 ' and nation= ' n001 ' multi-condition and relational query
SELECT * from Info where name= ' hu June ' or nation= ' n001 ' multi-condition or relational query
SELECT * from Car where price>=50 and price<=60 range query
SELECT * from Car where price between 60 and range query

Three: Fuzzy query
SELECT * from Car where Name '% type '% wildcard represents any number of characters
SELECT * from Car where Name '% audi% ' _ wildcard represents any one character
SELECT * from Car where Name like ' _ Horse% '

Four: Sort
SELECT * from Car ORDER BY price ASC in ascending order
SELECT * from Car ORDER BY price desc in descending order of prices
The SELECT * from Car ORDER by Price,oil is sorted by two columns, preceded by the primary

Five: Statistical function (aggregate function)
Select COUNT (Code) from Car query table how many data
Maximum value of select Max from Car fetch price
Select min (price) the minimum value from Car pickup
Select SUM (Price) The sum of the prices from Car fetch
Average of Select AVG (price) from Car fetch prices

Six: Group query
Select brand from Car GROUP by Brand has count (*) >2 query for all series with a quantity greater than 2

Seven: Paging query
SELECT * from Car limit 0, 5 skip a few data to fetch several data

Eight: Go to re-query
Select distinct Brand from Car



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