DQL (data Query Language)
A. Syntax
Select Column Name, ...
From table name
Where Condition expression
Order BY Column name (sort)
Eg:select Empno,ename,sal
From EMP
where empno=7788
Order BY Empno;
B. Alias as
Syntax: Column name as column alias
Eg:select ename as ' name ', sal as ' payroll ' from EMP;
C. Operations
1) Logical operation
And: Representation and (similar to && in Java)
Or: Represents or (similar to | | in Java) )
Not: Indicates an inverse
2) comparison operation
>,>=,<,<=,=,<>.! = (not equal to)
3) is null/is NOT null
Is null: Represents a column null
is NOT NULL: an example that represents a non-null
D. Constant query
Fixed line: Top N
Eg:select Top 5 empno,ename,comm from EMP;
Pro-rata: Top N percent
Eg:select Top 5 percent empno,ename,comm from EMP;
F. Sorting
Order BY column name, column name ... Asc/desc
ASC means: Descending
Desc: Ascending (default)
1 --SELECT ... 52 --From ... 13 --WHERE ... 24 --GROUP by ... 3 Press ... Grouping5 --Having ... 4 Packet filtering6 --ORDER by ... 67 8 --average salary for each department9 SELECTDEPTNO,AVG(SAL) fromEmpGROUP byDEPTNO;Ten --Employee wages for employees with a salary portion greater than 1000 per department One SELECTDEPTNO,AVG(SAL) fromEmpWHERESAL> + GROUP byDEPTNO; A --query is not available from January 1, 1981 to August 1, 1981 employee Information - SELECT * fromEmpWHEREHireDate not between '1981-1-1' and '1981-8-1';--Not to constrain the "reverse" operation of the condition
Example
Database (4)