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