_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › 3一豪Μ

Contents

1 覦覯1
2 覦覯2
3 覦覯3


螳 id螳 螳 磯殊 3覯 一朱 豪Μ 螳 觸螻 蟆曙磯. 讌レ 覦磯 覓殊企 襯 襷れ企瓦. れ 螻 蟾襾豪.

1 覦覯1 #

drop table #temp 
create table #temp(id varchar(20), win bit, dt datetime default getdate())
insert #temp(id, win) values ('a', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('a', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('a', 0) waitfor delay '00:00:01'
insert #temp(id, win) values ('a', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('a', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('a', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 0) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 0) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
--insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 0) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1) waitfor delay '00:00:01'
insert #temp(id, win) values ('b', 1)

;with temp
as
(
	select * , row_number() over(partition by id order by dt) rownum
	from #temp
), rs1
as
(
	select --*
		a.id
	,	a.rownum
	,	max(b.rownum) max_rownum
	,	max(b.dt) max_dt
	,	isnull(count(case when b.win = 1 and a.rownum-b.rownum <> 1 then 1 end),0) cnt
	,	isnull(min(case when a.rownum-b.rownum = 1 then convert(int,b.win) end),0) prev1_row
	from temp a inner join temp b
	on a.id = b.id
	and a.rownum in (b.rownum+1, b.rownum, b.rownum-1, b.rownum-2)
	group by
		a.id
	,	a.rownum
	having isnull(count(case when b.win = 1 and a.rownum-b.rownum <> 1 then 1 end),0) = 3
), rs2
as
(
	select *, row_number() over(partition by id order by rownum) rownum2
	from rs1	
)
select * 
from rs2
where prev1_row = 0 or rownum2 % 3 = 1
order by id, rownum

2 覦覯2 #

伎 Row 蠏狩蠍 襯 谿瑚 cross join 覃 .
4覯讌 伎 row螳 1 螻, 3覯讌 2覯讌 蠏碁Μ螻 row螳 豪Μ企 3一企.

3 覦覯3 #

sql襷螻 るジ 覦覯朱 豌襴.
ssis 螳 row 蠍磯 豌襴 襭 伎.
伎 螳 覓語 sql 伎碁Μ讌 .
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

一 レ . 蠏碁覃 轟蟆 る 螳 殊 襷 襷譟煙る 蟆企. 豺蟲れ 轟 襦 轟 蠏碁れ蟆 譴る 轟 螻 至鍵 蠏碁れ 襦 譬 豺蟲れ 譴 蟆企. 襦燕襦郁 襷 豺蟲襯 螳讌る 豺蟲螳 企. (企 るΠろ "蟆壱狩讌 讀蟇一"筝)