版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
createtableearnings--打工賺錢表(earnmonthvarchar2(6),--打工月份areavarchar2(20),--打工地區(qū)snovarchar2(10),--打工者編號snamevarchar2(20),--打工者timesint,--本月打工次數(shù)enumber(10,2),--每次賺enumber(10,2)--當月總收入insertintoearningsvalues('200912','北平','511601','',11,30,11*30);insertintoearningsvalues('200912','北平','511602','大凱',8,25,8*25);insertintoearningsvalues('200912','北平','511603','',30,6.25,30*6.25);insertintoearningsvalues('200912','北平','511604','大亮',16,8.25,16*8.25);insertintoearningsvalues('200912','北平','511605','賤敬',30,11,30*11);insertintoearningsvalues('200912','金陵','511301','',15,12.25,15*12.25);insertintoearningsvalues('200912','金陵','511302','',27,16.67,27*16.67);insertintoearningsvalues('200912','金陵','511303','小妮',7,33.33,7*33.33);insertintoearningsvalues('200912','金陵','511304','小俐',0,18,0);insertintoearningsvalues('200912','金陵','511305','雪兒insertintoearningsvalues('201001','北平','511601','',0,30,0);insertintoearningsvalues('201001','北平','511602','大凱',14,25,14*25);insertintoearningsvalues('201001','北平','511603','',19,6.25,19*6.25);insertintoearningsvalues('201001','北平','511604','大亮',7,8.25,7*8.25);insertintoearningsvalues('201001','北平','511605','賤敬',21,11,21*11);insertintoearningsvalues('201001','金陵','511301','',6,12.25,6*12.25);insertintoearningsvalues('201001','金陵','511302','',17,16.67,17*16.67);insertintoearningsvalues('201001','金陵','511303','小妮',27,33.33,27*33.33);insertintoearningsvalues('201001','金陵','511304','小俐',16,18,16*18);insertintoearningsvalues('201001','金陵','511305','雪兒',11,9.88,11*9.88);select*fromsumselectearnmonth,area,sum( fromearningsgroupbyearnmonth,areaorderbyrollupselectearnmonth,area,sum( fromearningsgroupbyrollup(earnmonth,cube按照月份,地區(qū)進行收入selectearnmonth,area,sum( fromearningsgroupbycube(earnmonth,area)orderbyearnmonth,areanullslast;groupbyearnmontharea以上三例都是先按照earnmonth分組,在earnmonth內(nèi)部再按area分組,并在area組內(nèi)統(tǒng) e總合groupbygroupgroupbyrollupgroupbyearnmonthgroupbycubeearnmontharea另外那個nullslast是把空值放在最后。(4)grou函在以上例子中,是用rollup和cube函數(shù)都會對結果集產(chǎn)生null,這時候可用grou函數(shù)來確認 函數(shù)用法,帶一個參數(shù),參數(shù)為字段名,1,Sql代 selectdecode(grou(earnmonth),1,'所有月份',earnmonth)月份,decode(grou(area),1,'全部地區(qū)',area)地區(qū), e)總金額fromgroupbycube(earnmonth,area)orderbyearnmonth,areanullslast;rank()overSql代 selectearnmonth月份area地區(qū),sname打工者,e收入rank()over(partitionbyearnmonth,areaorderby edesc)fromearnings;dense_rank()overSql代碼 selectarea,sname,edense_rank()over(partitionbyearnmonth,areaorderby edesc)paimingfromearnings;row_number()overSql代碼 selectearnmontharea,sname,erow_number()over(partitionbyearnmonth,areaorderby edesc)fromearnings;通過(5)(6)(7)rank,dense_rank,row_number結果集中如果出現(xiàn)兩個相同的數(shù)據(jù),那么rank會進行跳躍式的,但是dense_rank不會跳躍式的,兩個第二接下來還是第三row_number最牛,即使兩個數(shù)據(jù)相同,也不一樣sumSql代 selectearnmonth月份area地區(qū),sname打工者, e)over(partitionbyearnmonth,areaorder e)總收入fromSql代 selectdistinctearnmontharea e)over(partitionbyearnmonth,area) e)over(partitionbyearnmonth,area) e)over(partitionbyearnmonth,area) e)over(partitionbyearnmonth,fromlaglead求出每個打工者上個月和下個月有沒有賺錢 e大于零即為賺錢Sql代 selectearnmonth本月sname打工者 e,0),0,'沒賺','賺了'),1,0)over(partitionbysnameorderbyearnmonth)上月 e,0),0,'沒賺','賺了'),1,0)over(partitionbysnameorderbyearnmonth)下月from說明:LagLeadNN(可以是其他字段的數(shù)據(jù),比如根據(jù)字段甲查詢上lag(value_expression[,offset][,default])over([query_partition_clase]order_by_clause);lead(value_expression[,offset][,default])over([query_partition_clase]order_by_clause);value_expr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 第二單元(單元測試)2024-2025學年統(tǒng)編版語文三年級上冊
- 江西省大余縣重點達標名校2024年中考數(shù)學模擬試題含解析
- 第五單元 交流平臺與初試身手(教學設計)-2024-2025學年統(tǒng)編版語文五年級上冊
- 中班安全課件《電的用處多》
- 利川市土地整治施工組織設計
- 南京市政府大學生合同制
- 人教版小學數(shù)學五年級下冊課件:3.2長方體和正方體的表面積(共29張)
- 高中物理第十九章原子核6重核的裂變課件新人教版選修3-
- 八年級政治上冊人教版政治競爭-合作-課件人教版公開課教案課件
- 人教小學數(shù)學三年級下冊:第1單元位置與方向(一)第1課時認識生活中的方向課件
- 傷寒副傷寒消毒要求及方法
- 三相分離器操作改終內(nèi)容
- 電氣火災原因技術鑒定方法第3部分成分分析法
- 國際學術會議海報模板5-academic conference poster model
- 煙囪支架施工方案
- 機場停機坪保潔管理辦法
- (標準件)常用螺絲規(guī)格表
- (可修改)北京醫(yī)院編碼1.doc
- 《經(jīng)濟體制改革》精品教案
- BSCI風險評估文件-11社會責任風險分析評估
- 產(chǎn)品可追溯流程圖圖
評論
0/150
提交評論