oracle查询案例,2道经典的oracle查询案例
第一題:
第一題:
直接貼代碼:
select Id,Name,Money,(select Money from test1 a where a.Id = decode(b.Id - 1,0,null,b.Id-1)) Money1 from test1 b;
經(jīng)典的子查詢,注意的就是null值的處理問題,decode或者case是oracle很重要的單行函數(shù)。
例如:漲工資的例子: select ename,job,sal 漲前, decode(job,'PRESIDENT',sal+1000, 'MANAGER',sal+800, sal+400) 漲后 from emp;
等同于:select ename,job,sal 漲前,case job when 'PRESIDENT' then sal+1000
when 'MANAGER' then sal+800
else sal+400
end 漲后
from emp;
第二題:
代碼: select CI_ID,wm_concat(STU_NAME) from ( select CI_ID, STU_NAME
from? pm_ci p1, pm_stu p2
where
STU_ID = to_number(substr(p1.STU_IDS,1,1)) or
STU_ID = to_number(substr(p1.STU_IDS,3,1)) or
STU_ID = to_number(substr(p1.STU_IDS,5,1)) or
STU_ID = to_number(substr(p1.STU_IDS,7,1))
) group by CI_ID;????????? //行轉(zhuǎn)列函數(shù) wm_concat ,還有一個思路就是 in方法,把1,2,3,4放在in()里面,這里就不演示了。
總結(jié)
以上是生活随笔為你收集整理的oracle查询案例,2道经典的oracle查询案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里巴巴备案(阿里做备案)
- 下一篇: 网站后台怎么替换图片(如何替换网站中的图