sql语句收藏
收集自網絡,方便自己,方便他人
1 if object_id('[aaa]') is not null drop table [aaa] 2 go 3 create table [aaa]([地區] varchar(4),[內容] varchar(45)) 4 insert [aaa] 5 select '中國','021sp.html|管材|4355;028sp.html|建筑材料|3209' union all 6 select '中國','023sp.html|材|4356;025sp.html|建|9209' 7 go 8 9 select a.地區, 10 內容=substring(a.內容,b.number,charindex(';',a.內容+';',b.number)-b.number) 11 from [aaa] a 12 join master..spt_values b on b.type='P' 13 where charindex(';',';'+a.內容,b.number)=b.number 14 15 /** 16 地區 內容 17 ---- --------------------------------------------- 18 中國 021sp.html|管材|4355 19 中國 028sp.html|建筑材料|3209 20 中國 023sp.html|材|4356 21 中國 025sp.html|建|9209 22 23 (4 行受影響) 24 **/ 按分隔符拆分記錄 1 select id, len(nr) - len(replace(nr,'a' , '')) from temp 字段中字符串出現次數?
轉載于:https://www.cnblogs.com/knightyj/p/5888824.html
總結
- 上一篇: C#全屏随机位置显示图片的小程序
- 下一篇: spark on yarn :state