乙個很BT的彙總演算法

2022-04-08 06:27:13 字數 1798 閱讀 7059

godeclare @n int = 1;

while(@n < 1000)

begin

insert into test values(char(65+((cast(rand()*100 as int)) % 26)),char(65+((cast(rand()*100 as int)) % 26)),char(65+((cast(rand()*100 as int)) % 26)),char(65+((cast(rand()*100 as int)) % 26)),char(65+((cast(rand()*100 as int)) % 26)));

set @n += 1;

endcreate table [user](name char(1));

goinsert into [user]

select 'a' as name 

union all select 'b'

union all select 'c'

union all select 'd'

union all select 'e'

union all select 'f'

union all select 'g'

union all select 'h'

union all select 'i'

union all select 'j'

union all select 'k'

union all select 'l'

union all select 'm'

union all select 'n'

union all select 'o'

union all select 'p'

union all select 'q'

union all select 'r'

union all select 's'

union all select 't'

union all select 'u'

union all select 'v'

union all select 'w'

union all select 'x'

union all select 'y'

union all select 'z'

goselect t.name,sum(t.c1cnt) as c1,sum(t.c2cnt) as c2,sum(t.c3cnt) as c3,sum(t.c4cnt) as c4,sum(t.c5cnt) as c5 from

(select u.name, case when t.c1 = u.name then t.cnt end as c1cnt

,case when t.c2 = u.name then t.cnt end as c2cnt

,case when t.c3 = u.name then t.cnt end as c3cnt

,case when t.c4 = u.name then t.cnt end as c4cnt

,case when t.c5 = u.name then t.cnt end as c5cnt

from [user] u,(select c1,c2,c3,c4,c5,count(1) as cnt

from test

group by grouping sets((c1),(c2),(c3),(c4),(c5))) as t

) as t

group by t.name

以上示例只是應一位大蝦寫出來的,在大資料量操作上,不敢恭維.

本示例純屬戲作.正規應用下,要保證資料量足夠小,方可使用. 

乙個很奇怪的問題

if equipmentlist.size 0 string equipidarray new string 3 for int i 0 i equipmentlist.size i element equipment element equipmentlist.get i string equip...

乙個很基本的分頁Procedure

很基本很基本很基本很基本很基本很基本很基本很基本,沒辦法!code 1 2 3假設500行資料,分頁,每頁10行,可分為50頁。45 設計procedure實現該需求67 8傳入三個引數,乙個每頁顯示的條數pagesize 乙個是當前頁pagecount 910 pagesize 每頁顯示的條數 1...

乙個聰明女人的嫁人經驗,很實在很犀利

1.女生還是要努力讓自己出色些,從能力到容貌。台灣有名廣告詞 認真的女人最美麗。每個人都有選擇自己生活方式的權利,但一定要認真。對自己 對工作 對生活。這樣的女人就算不是天生麗質,也有一種自信從容的美 也只有這樣的美,才能和時間對抗,其實也是好男人欣賞的型別。可能很多姐妹不是工作上很出色的人,那麼能...