SQL Single Table Query

Source: Internet
Author: User
Tags aliases

---restore content starts---

SELECT statement Format:

SELECT [all| DISTINCT] < target column expression >[,< target column expression;
From < table name or view name >[,< table name or view name >]...| (SELECT statement)
[as]< aliases >
[WHERE < conditional expressions >]
[GROUP by < column name 1> [having < conditional expression >]]
[ORDER by < column name 2> [asc| DESC]];

A query statement can be divided into three parts:

Select clause: Specify the property columns to display
FROM clause: Specifies the Query object (base table or view)
WHERE clause: Specify query criteria

GROUP BY clause: Groups the results of the query by the values of the specified columns, which have a tuple of equal values for the column. Aggregate functions are typically scoped in each group.
Having phrase: Only groups that meet the specified criteria will be output

ORDER BY clause: Sort the query result table in ascending or descending order of the specified column values

1. SELECT:

The < target column expression for the 1.1 Select clause > can be either an attribute column in a table or an expression

SELECT Sname,2018-sage from Student;

SELECT Sname, ' Year of Birth: ', 2018-sage,LOWER(sdept) from Student;

/* Use aliases */

SELECT Sname NAME, ' Year of Birth: ' Birth, 2018-sage BIRTHDAY, LOWER (sdept) DEPARTMENT from Student;

1.2 Removing duplicate rows from values

Specify DISTINCT keywords to remove duplicate rows from the table. If no distinct keyword is specified, all is the default

SELECT DISTINCT Sno from SC;

Common Query conditions:

Query criteria Predicate
Comparison =, <, >=, <=,! =, <>,!>,!<; Not+ The above comparison operators
Determine scope Between and, not between and
Determining the Collection In, not in
Character matching Like, isn't like
Null value Is null, was NOT NULL
Multiple conditions (logical operations) And, OR, not

SQL Single Table 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.