oracle语法 续
上一篇 / 下一篇 2014-05-27 17:29:17 / 个人分类:甲骨文
使用表达式51Testing软件测试网:QX#DL/|+Jk8R
=====================================================================
.U/zWgQ"o)n)I w0
-K,xjM
b2k2S0Select ename || ' 是一位 ' || job As 雇员细节,51Testing软件测试网8If&n4`Hu8S'Q
to_char(hiredate,'yyyy-mm-dd') As 雇佣时间,51Testing软件测试网 gd?L2mn3F3P
sal*1.2
7yMhc2K.j]0From emp;
6[-q]_m051Testing软件测试网%v){?v*|.NS
=====================================================================51Testing软件测试网Sg&|7YR;P e1b
取消重复行 distinct
\j
sC%N u0=====================================================================51Testing软件测试网;W2T/Qo5LbP
5a9|%b1L"K:P$LuO,| Y0Select Distinct deptno, job From emp;51Testing软件测试网9q~9bpx
Jy{
Yv;R*tG0=====================================================================51Testing软件测试网X7M p/b`_7l
指定列排序 order by51Testing软件测试网J#Z"TkT0zn7R-@&T6F
=====================================================================51Testing软件测试网Nz0_1g6W
asc 升序,desc 降序51Testing软件测试网K9VP#UPu Y
--------------------------------------------51Testing软件测试网
S+iu1KV9P-H
]
Select * From emp51Testing软件测试网%g%`9Jn0CX
where sal between 1500 and 3000
~RL5t]'d0Order By deptno Desc,ename;
t p8VQjp0
N#I*FHGX
kv0--------------------------------------------51Testing软件测试网+pY orK
K&cf6XaG
如果使用dsitinct,排序列必须是选择列51Testing软件测试网n-?X7VQ$}D%J#d#g
---------------------------
he;o$y"q#ynm&nfQ0select distinct depton, job
0M1]8j4B,N] H'C ~$T0from emp51Testing软件测试网k2m}z$M'UB
order by job;
wKjm y@V0---------------------------------------------51Testing软件测试网j0z5W+`,V:d6U&Dr-Nn
order by 子句必须是最后一个子句51Testing软件测试网&Du)N{:A{~+|w?
============================================================
:xe2aL
F/Z7M S0 分组查询语句51Testing软件测试网1G1lB7e:yyL
============================================================
'iamMM
^%CB01。组处理函数不能出现在 where 子句中
"}L q4Ey:g02。选择列表中的列、表达式,必须出现在 group by 子句中51Testing软件测试网[7s+G QKf)R
3。组处理函数中可以指定 all 和 distinct51Testing软件测试网+H)i;b2OU
============================================================51Testing软件测试网m2X4Wo
a
HNs*W9]
分组函数51Testing软件测试网` DxsD
---------------------------------------51Testing软件测试网-M%~u@ T-^
select avg(sal) as avg1,51Testing软件测试网
HU.\/E_I
avg(distinct sal) as avg2,51Testing软件测试网
L0sm"{;few!M1g3D
max(sal) as max,
,p
_wBEV@0 min(sal) as min,
fh
TZP1YA0 sum(sal) as sum,51Testing软件测试网9f)x"L*gt"Q.u RC0|
count(*) as cnt1,51Testing软件测试网4Xu,b.jl L6E9Ke
count(sal) as cnt2,51Testing软件测试网MourS_ cD[
count(distinct sal) as cnt351Testing软件测试网1W$CC#a[vO7H!J `
from emp
3OZ'\oh9e:n6x0where deptno = 30;
$X,WE.k^
IdU0
&j*~W"?y*h%mY9?0============================================================
A|y#or hX,Q0单列分组51Testing软件测试网6y? q%n
c"]9V
---------------------------------------------
&W~n){7zo9\nh0select deptno, avg(sal), max(sal) from emp
SM6d0?v$k%|0group by deptno;
q|,z5V:x_8vF{051Testing软件测试网,h/wz|G
select deptno, avg(sal), max(sal) from emp
6T5^)h~O`Y0group by deptno51Testing软件测试网M![)|^
WY
order by avg(sal);51Testing软件测试网0bFo3KTG)O'P
9uu;U\8@$zos3R1\j0============================================================51Testing软件测试网9[^,`PH/sT'V;n
多列分组
*Mn PP!v0---------------------------------------------
'H"^#J:L d+hz!fV0select deptno, job, avg(sal), max(sal), from emp
tD:P(R9l xV0group by deptno, job;51Testing软件测试网7g
gs1^8kV
n5T
E1v4i*[ fNd(^)?0============================================================51Testing软件测试网;Cis$c$t"C5I
============================================================
Z,_Hbcx/[]0rollup 用于生成横向统计信息
o-bsvo;kgY$p0--------------------------51Testing软件测试网;[['n;W6VI(f
Select deptno, job, Avg(sal), Max(sal) From emp
)a
b1vyeP+l8Mop-i0Group By rollup(deptno,job)
:`"a+sil _4})D051Testing软件测试网1[7f~0lb;_zG R
--------------------------------------------------
|$A9M2d2nH6T"X0cube 用于生产纵向统计信息51Testing软件测试网#h8C$Jh2w
------------------------------51Testing软件测试网d b/Ip:F\z
Select deptno, job, Avg(sal), Max(sal) From emp51Testing软件测试网inq$i^ uD
Group By Cube(deptno,job)51Testing软件测试网R6RYvrKf
M
V)m
XniL{$Qr051Testing软件测试网;o0g^c@h0qD
============================================================51Testing软件测试网}e2OBOcc
having 子句
"qt? M7Oe'Wm:dG0============================================================
v0z j2c_)b q8xg0select deptno, avg(sal), max(sal) from emp
$`[ @I,A^%wM7cc{G0group by deptno
4P~ ^fd,n6|F&w0having avg(sal) > 2000;51Testing软件测试网(JFuX1A
vq#A
51Testing软件测试网|s/\&P$oSf#FZ
不等连接51Testing软件测试网;\|K*~)C[O@}!{
----------------------------51Testing软件测试网;N9k Ha5g*[i
Select e.ename, e.sal, s.grade
J%u8}+R|$Q!ru'?[V0From emp e,salgrade s
1Yh\d!Dxm3nVB,E0Where e.sal Between s.losal And s.hisal 51Testing软件测试网,ou|.[`*~"@
And e.deptno = 30