?? 統計一個表中某個字符出現最多的字母.sql
字號:
/*
統計一個表中某個字符出現最多的字母
*/
--創建數據測試環境
create table #tb(a varchar(200))
insert into #tb
select 'abcdasdlfjaslk;dfqwoieurwhft'
union all select 'a;sldkjfal;sopqwhtdlkdafrfgsgasdfh'
union all select 'asldfkworufgsea87y9oqwpe tchgwccmnqnw3 '
--為字符分拆準備臨時表,top 200 是根據要分拆的字符串的最大長度而定的,
--在測試中,因為a字段的最大為200,故這里用 top 200
select top 200 id=identity(int,1,1)
into #aa from
(select top 100 id from syscolumns) a
,(select top 100 id from syscolumns) b
,(select top 100 id from syscolumns) c
--得到結果
select top 1 substring(a,b.id,1)
from #tb a,#aa b
where substring(a.a,b.id,1)<>''
group by substring(a.a,b.id,1)
order by sum(1) desc
drop table #tb,#aa
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -