Use the SELECT statement to retrieve data

select instructions for SQL database
SELECT statement is used to select data from the database. (Not case-sensitive command, select the name and value addition to some special meaning characters are not case sensitive, must be added at the end from;)

1. Use
SELECT column_name from table_name;
. 1
SELECT column select those identified
from selected identifier table from which

Examples
SQL> select * from dept;

The LOC the DNAME the DEPTNO
---------- -------------- -------------
10 NEW YORK the ACCOUNTING
20 is DALLAS s
30 the SALES CHICAGO
OPERATIONS the BOSTON 40
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
query table dept information for each line (each column here is meant *)

2. arithmetic expressions
using the arithmetic operators to create expressions containing numbers, and date data (priority and mathematics, as after the first addition and subtraction multiplication and division, parentheses the first operator in parentheses)

Operator Description
+ plus
- minus
* Multiplication
/ semicolon
instance
the SQL> SELECT SAL, SAL + 2000, ename
2 from EMP;

SAL + SAL the ENAME 2000
---------- ----- ---------- -----
800 2800 SMITH
1600 ALLEN 3600
1250 3250 WARD
2975 is 4975 JONES
1250 MARTIN 3250
2850 4850 BLAKE
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
queries emp table sal, sal + 2000, ename information

3. null null
null is an unknown value, or a space is not 0 (when there is no calculation result of adding null)

实例
SQL> select ename,sal,12*sal+comm
2 from emp;

* SAL + SAL 12 is the ENAME COMM
---------- ---------- -----------
SMITH 800
ALLEN 1600 19500
WARD 1250 15500
JONES 2975 is
MARTIN 1250 16400
BLAKE 2850
CLARK 2450
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
because it is not unknown null output (if we want to calculate a null herein function nvl (,) to give a nul value)

SQL> select ename,sal,12*sal+ nvl(comm,0)
2 from emp;

* SAL + SAL 12 is the ENAME of the NVL (COMM, 0)
---------- ---------- ------------------
9600 800 SMITH
ALLEN 1600 19500
WARD 1250 15500
JONES 2975 is 35700
MARTIN 1250 16400
BLAKE 2850 34200
CLARK 2450 29400
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
NVL (,) function is used to specify how nvll value assigned to a null value

4. Define column alias
to the column aliases redefined columns (in addition to numbers, other characters need to add "")

column_name as the SELECT "column"
from table_name;
1
2
to add as required in the original column name after the column definition when the alias "" or simply a space and a new column name (defined only temporary, not permanent preservation)

5. The connector ||
|| connect the column to column, in addition to numeric character need to add '' (front and rear spaces have ||)

SQL> select 'my name is ' || ename
2 from emp;

'Mynameis' || the ENAME
---------------------
My name IS SMITH
My name IS ALLEN
My name IS WARD
My name IS JONES
My name IS MARTIN
My name IS BLAKE
My name iS CLARK
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
put in the form of a table of contents output phrases

6. deduplication DISTINCT
DISTINCT column duplicate values removed

SQL> select distinct job,deptno
2 from emp;

The DEPTNO the JOB
--------- ----------
MANAGER 20 is
PRESIDENT 10
the CLERK 10
SALESMAN 30
ANALYST 20 is
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
to view the information in a column to remove duplicate values
--------------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/10961762.html