記錄,以免忘記
原始資料如圖所示:
**為:
select '[ '+time+' ]' from test1 for xml path('')
select '[ '+time+' ]' from test1 for xml path('time')
結果為:
處理二:將uid,mid以xml的格式儲存,xml檔案的行節點別名為uid_mid,uid,mid的別名分別為u,m
**:
select uid as u, mid as m from test1 for xml path('uid_mid')
結果:
處理四:將同一uid的所有微博id拼接成一行,用逗號隔開,以uid分組,並且插入到新錶test2中
**為:if object_id('test2', 'u') is not null
drop table test2
select uid,
(select mid+',' from test1
where uid=a.uid
for xml path('')) as mid_new
into test2
from test1 a
group by uid
結果為:
處理五:將同一uid的所有微博id拼接成一行,用逗號隔開,以uid分組,並且插入到新錶test3中,與上面的區別在於select出來的內容沒有最後的分隔符『,』
**為:if object_id('test3', 'u') is not null
drop table test2
select b.uid, left(mid_new,len(mid_new)-1) as mid_new
into test3
from
(select uid,
(select mid+',' from test1
where uid=a.uid
for xml path('')) as mid_new
from test1 a
group by uid) b
結果為:
oracle 批量更改所有表的同一字段型別
經常需要oracle中的所有的字段的型別更改為另外乙個型別,可以考慮利用如下 此處的demo為將nvarchar2轉為varchar2型別並且字段長度保持不變。declare cursor c tab is select from user tab columns t where t.data ty...
MySQL對某一字段去重
mysql有乙個去重關鍵字distinct,但是如果查詢的字段有很多,而想要去重的字段只是其中的某乙個,那麼僅僅用distinct是完成不了的,distince只能做到你查詢的那些欄位都是重複時才會去重。比如有一張使用者表的資料是這樣的 這裡我們本意是想查出一條資料,如果是這樣寫sql語句 sele...
Mysql 同一欄位多值模糊查詢
同一欄位多值模糊查詢,使用多個or進行鏈結,效率不高,但沒有更好的解決方案。有看到charindex 關鍵字,可查詢結果並不是模糊,舉個栗子 例如select from table where charindex name 張三,李四 0 二 同一值多字段模糊查詢,使用concat關鍵字,舉個栗子 ...