Sql使用日常總結

2021-07-09 04:35:12 字數 1443 閱讀 5016

//乙個字段裡面的值是"

a,b,c",分成三行讀取

with

t1 as

( select

'a,b,c'

c1 from

dual

)select

distinct

regexp_substr(c1,

'[^,]+'

, 1, level

) c1

from

t1connect

by level

<=

length

(c1) -

length

( replace

(c1,

',', ''

)) +

1--update並且關聯其他表

update

maintenance_special t

set(t.accountidofissued, t.departmentidofissued) = (

select

a.id, d.id

from

oura_account a

left

join

oura_department d on

a.department_id = d.id

where

a.name = t.accountofissued )

where

exists (

select

1 from

maintenance_special t

left

join

oura_account a on

t.accountofissued = a.name

left

join

oura_department d on

a.department_id = d.id)

--遞迴查詢

select wmsys.wm_concat(t.id) ids from

(select d.id from oura_department d

start with d.id=14

connect by prior d.id=d.parentdepartment_id) t

--時間統一佔位符

where a.cleardt >= trunc(?) and a.cleardt < trunc(?+1)

--row_number()  over(...)使用

簡單的說row_number()從1開始,為每一條分組記錄返回乙個數字,這裡的row_number() over (order by xlh desc) 是先把xlh列降序,再為降序以後的沒條xlh記錄返回乙個序號。 

日常SQL總結

case length cast bal.asset acct as string when 12then 資金賬戶 when 16then 理財帳戶 else 其他 end case後可以加入條件在寫when,length string 為string的字元長度 length 括號裡不僅可以是st...

SQL日常總結(SQL Server)

變數分為區域性變數和全域性變數 是sql中標量變數開頭的必須字元,sql規定,區域性標量變數必須以 開頭,全域性標量變數以 開頭,全域性標量變數不許宣告,直接使用即可 區域性變數的使用是先申明再賦值。而全域性變數由系統定義和維護,可以直接使用,但一般不自定義全域性變數 區域性變數的名稱必須以標記 作...

mysql日常使用總結

1.在mysql中 double型別字段 不能指定長度,如 alter table pur purchase item config history change column safe stock day safe stock day double 20 not null comment 安全水位...