select row_number() over(order by sal/排名列/ desc ) as 排名 ,sal from empaa.deptno as 部門,
nvl(aa.ename,『小計』) as 員工名,
sum(aa.sal) as 工資
from emp aa
group by grouping sets((aa.deptno,aa.ename),aa.deptno)–按照部門,員工名分組;在每個部門上新增小計
listagg(b, 『分隔符』) within group( order by b)select * from 表名a aa where aa.rowid !=(select max(bb.rowid)
from 表名a bb
where bb.欄位a=aa.欄位a
)
列名select
regexp_substr(sys_connect_by_path(列名,'分隔符'),'[^,]+',start_index,lenngth)
from table
start with 列名 = 42001
connect by prior 上級列名 = 列名
上級列名
42001
42003
42001
42004
42003
找到用42001作為上級列名的資料 >> 拿它的列名42003作為上級列名再次找對應列資料》直到遞迴結束
select 姓名,tt.收支標誌,tt.金額,年齡
from(
select
『張三』 as 姓名
,700 as 收入
,300 as 支出
,17 as 年齡
from dual
) unpivot(金額 for 收支標誌 in (收入,支出)) tt
給自己的備註:下面的**處理的是有應用層的jobid,由上往下查詢它依賴的job
select xmlagg(xmlparse(content cnt||』,』) order by cnt).getclobval() as 資料集注:nxsods.job_dependency(表名)、job_id(科目編碼)、pre_job_id(上級科目編碼)from(
select
sys_connect_by_path(pre_job_id,』,』) as cnt
from nxsods.job_dependency
start with job_id = 1006
connect by prior pre_job_id = job_id
)
查詢出來的資料集在excel操作:
之後去重
大概樣子
select id,aa.starttime,aa.endtime,nvl(aa.starttime-lag(aa.endtime) over(partition by id order by aa.starttime ),0) cnt可以使用兩個表的自連線。具體需要根據實際業務再行研究from test4 aa
select aa.,bb.,to_char(case when aa.starttime>bb.starttime then aa.starttime else bb.starttime end,『yyyy-mm-dd hh24:mi:ss』)||』 至 '||要點:表間關聯可以使用不等式關聯(也就是區間)。還有一種解題方式是使用函式,暫時未找到to_char(case when aa.endtime>bb.endtime then aa.endtime else bb.endtime end,『yyyy-mm-dd hh24:mi:ss』) as 差額
ORACLE常用函式總結
時常忘記,但是用得十分頻繁 nvl nvl exp1,exp2 exp1為null,返回exp2,exp1不為null,返回exp1 主要使用者轉換null值 nullif nullif exp1,exp2 exp1 exp2,返回空,不等返回exp1 coalesce coalesce exp1,...
oracle常用函式總結
目錄 nvl2.1 decode 函式簡介 1 sign 函式.3 oracle 中的union union all intersect minus 3oracle trim 函式.7 oracle trunc 函式的用法 8 lpad 用法.10 oracle translate 詳解 例項.10...
Oracle常用函式總結
1 concat和 concat連線兩個字元,可連線多個字元 select concat a b from dual ab select a b c from dual abc 2 replace 將要更改的字串 被替換掉的字串 替換字串 select replace abc b 1 from du...