A preliminary study of the database (understanding of basic concepts and the charm of query statements)

Source: Internet
Author: User

The SQL language consists of four parts:

Data definition Language (DDL): For example,create, DROP, alter and other statements;

Data manipulation Language (DML): For example,Insert, UPDATE, delete and other statements;

Data Query Language (DQL): For example,select statement;

Data Control Language (DCL): For example,Grand, REVOKE, commit, rollback and other statements.

* Important query statement syntax and how to use it:

order By default ascending order (ASC)

ORDER BY desc descending order

order by can be sorted by different fields

That is: SELECT * FROM table name order by (fields requiring ascending order), Dese (fields requiring descending)

If you want to query a table but a field is empty, you cannot use 0 to indicate that you want to use IsNull

For example:

Count each person's annual salary and sort from low to high

Select Person Name field (Sal+isnull (comm,0)) * 12 year salary from table name order by annual salary

Common functions:max (), Min (), AVG (), sum (), COUNT ()

Number of enquiries:

--Select COUNT (*) from table name

Check the display of names and wages of employees above average wage:

--select name, sal from table name where sal> (select AVG (SAL) from table name)

Having often combined with group by, you can filter the results of a grouped query

Query the department number and its average salary below 2000 of the average salary:

Select AVG (SAL), Department number from table name GROUP by department number having AVG (SAL) <2000

More knowledge of the database, next time more.

A preliminary study of the database (understanding of basic concepts and the charm of query statements)

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.