oracle语法 续
上一篇 / 下一篇 2014-05-27 17:29:17 / 个人分类:甲骨文
s%LPH4T@1z%n#h:|
W/P0使用表达式51Testing软件测试网Q(_][ F?
=====================================================================51Testing软件测试网5a+v&d8{J-\:~2K;|
51Testing软件测试网CoI1r}};u
Select ename || ' 是一位 ' || job As 雇员细节,51Testing软件测试网Xk5oh3S/ZO
to_char(hiredate,'yyyy-mm-dd') As 雇佣时间,51Testing软件测试网H
H
~8u*`I6|0@;V7]'gp
sal*1.251Testing软件测试网8W6K;m#D-B(dK-T9C
From emp;
o$Gm2z&t3B$yjt051Testing软件测试网%kpy@bIWE%RE/a
=====================================================================
aYi8U:d*Y? |0 取消重复行 distinct51Testing软件测试网}[1U;T A+^$r
=====================================================================51Testing软件测试网g*B#d8Nte
51Testing软件测试网8e?R&Y+n.gT
Select Distinct deptno, job From emp;51Testing软件测试网S$|O!uz K,|
51Testing软件测试网5a}$V+J
`^PX*Z#~
=====================================================================51Testing软件测试网(?!Nn4Gmq~8}3d1UQ+T
指定列排序 order by51Testing软件测试网8kAt
r'|.v%im y
=====================================================================51Testing软件测试网olm6LUH
asc 升序,desc 降序51Testing软件测试网*@%I\.F'\"m
M
--------------------------------------------51Testing软件测试网,C6Vs%p$[XV
Select * From emp
0R]N]Q,N0where sal between 1500 and 3000
,ci{nqyY$K0Order By deptno Desc,ename;
9r)}-Y\8w7w _5OJ0uW4\0
9g+i7p|@^9_a2VC$x0--------------------------------------------
I3[8c1c!V8TtwL0如果使用dsitinct,排序列必须是选择列51Testing软件测试网7L%sBQ f `,m2P
---------------------------
@8Hi \|Y!RH0select distinct depton, job
~!f-C |\5b@Le0from emp51Testing软件测试网8y5eq+})y S3AQ
order by job;
_bn[u?c-p'K0---------------------------------------------51Testing软件测试网)}6[,}{K1]8|_@"bz4Q
order by 子句必须是最后一个子句
!r!]`*u[`}9e%d0============================================================51Testing软件测试网"[VO*a~mu.A
分组查询语句
;|~8AW#V4P/xZ3IA d~0============================================================
%ZPNj$dO;D01。组处理函数不能出现在 where 子句中
0_}3J,{mX qA02。选择列表中的列、表达式,必须出现在 group by 子句中51Testing软件测试网/xV?GZGgJ
3。组处理函数中可以指定 all 和 distinct51Testing软件测试网 Bs@b$_{)I
============================================================
'P5]kQ4|Y0分组函数
-L|3m&KB*|:b(x0---------------------------------------
py,vzrF0select avg(sal) as avg1,51Testing软件测试网1CL$bS PCv
avg(distinct sal) as avg2,51Testing软件测试网yK{$sq!D.{']']
max(sal) as max,51Testing软件测试网K7L*l$iR$\PJul
min(sal) as min,51Testing软件测试网R:gg
[$L}N4X.\5m*c
sum(sal) as sum,51Testing软件测试网2W*g*{3b(j0q,dB
z\d
count(*) as cnt1,
(q[OI:U
Q!s:B%A|5W0 count(sal) as cnt2,51Testing软件测试网2pA*l~tE
x
count(distinct sal) as cnt351Testing软件测试网e7H~KT
from emp
|erS(z!|0where deptno = 30;51Testing软件测试网$w8k2Z1DZ3a9g3c
51Testing软件测试网ZH7\#LQh:{5o
============================================================
A!cX E$U0单列分组51Testing软件测试网+k/x~&{}I.QA3[
---------------------------------------------51Testing软件测试网?~4FeQ U
select deptno, avg(sal), max(sal) from emp51Testing软件测试网o"L~G5nv*KG
group by deptno;51Testing软件测试网Bwo?;pO
51Testing软件测试网
]6@!KgRKKWd9E$l
select deptno, avg(sal), max(sal) from emp51Testing软件测试网N7P\1MX5fD)j]
group by deptno51Testing软件测试网4p)AhAu3Sjb8K*|
order by avg(sal);51Testing软件测试网&V-A2wZ!NM9Dr@$E
Bc4G]w.tq0============================================================
,}zhWh2o0多列分组
&VjA/y9yA z/A-d$h0---------------------------------------------51Testing软件测试网1d1d
~zI_&|
select deptno, job, avg(sal), max(sal), from emp
q!ULjZ9}!c0group by deptno, job;
WG;{*r6^0
*YA$?S(DJ8w_0============================================================
;Q3c5l ^6v5ja
e0============================================================51Testing软件测试网
b!`d{.M0[*gO
rollup 用于生成横向统计信息
0x-p#H~*y:?M ~0--------------------------
#j[bzC#h
O4R-Is3H0Select deptno, job, Avg(sal), Max(sal) From emp
2p;CfNy4X/v0Group By rollup(deptno,job)51Testing软件测试网&Rw&x{#h il
RAr7h^T0--------------------------------------------------51Testing软件测试网B2`MLw8a!?
cube 用于生产纵向统计信息51Testing软件测试网7R.f/uw!@aP$^.y
------------------------------
(v'N~ [M G]u0Select deptno, job, Avg(sal), Max(sal) From emp
]4_?BRF0Group By Cube(deptno,job)51Testing软件测试网%[x:na$Rk;`T
&q0C