—
层次查询—爬树查询
empno mgr
起点—找谁的 start with
方向—上级 下属 –prior
指明关系的列 empno mgr –connect by
select SYS_CONNECT_BY_PATH(ename, ‘/’) from emp start with ename=’SCOTT’ connect by prior empno=mgr;
king
jones
SCOTT
sdsdsds
blake
aaaaa
clark
bbbbb
SYS_CONNECT_BY_PATH(ename, ‘/’)
scp xxx 172.16.100.251:/
—-对照关系
select
sal,
e.deptno,
avgsal
from
emp e ,
(select deptno,avg(sal) avgsal from emp group by deptno) e2
where
e.deptno=e2.deptno
order by
2
/
~
~
SQL> select ename,deptno from emp where (select count(*) from emp e where sal>emp.sal and deptno=emp.deptno)<2;
select
e.deptno,
sal my_sal,
deptno_sal,
total_sal
from
emp e ,
(select deptno,avg(sal) deptno_sal from emp group by deptno) e2,
(select avg(sal) total_sal from emp) e3
where
e.deptno=e2.deptno
order by
1
/
SQL> select sal,avg(sal) over( partition by deptno ) dept_sal,avg(sal) over() total_sal from emp ;
分析函数
~
SQL> select sal,ename from emp order by sal desc;
SAL ENAME
———- —————dense_rank rank row_number
5000 KING 1 1 1
3000 FORD 2 2 2
3000 SCOTT 2 2 3
2975 JONES 3 4 4
2850 BLAKE 4 5 5
rank dese_rank row_number
yyyy rrrr rr-yy
DQL
DDL
CREATE DROP ALTER RENAME TRUNCATE COMMENT
create table T1 (列名 数据类型 约束 ,列2 数据类型2 约束2 ,……..)
字符 varchar2 变长
char 定长
日期
date 入职日期 出生年月日 秒 天
timestamp 时区 秒力度细 12:11:15.11111111 +8:00
china japan
4 A + 8:00 5 9:00
数字
number
create table 我 (id number);
select * from 我;