Are you on SQL 2008 or above?
If not you need to change query as
declare @temp2 table
(
cola varchar(100),
colb varchar(100),
colc varchar(100)
)
insert @temp2 select 460,'10100100','free'
insert @temp2 select 461,'10100101','free'
insert @temp2 select 462,'10100100','free'
insert @temp2 select 464,'10100100','assigned'
insert @temp2 select 465,'10100101','free'
insert @temp2 select 466,'10100100','free'
insert @temp2 select 467,'10100101','free'
insert @temp2 select 468,'10100101','free'
insert @temp2 select 469,'10100100','free'
insert @temp2 select 470,'10100100','free'
insert @temp2 select 472,'10100101','free'
insert @temp2 select 475,'10100100','free'
insert @temp2 select 477,'10100100','free'
insert @temp2 select 478,'10100101','free'
insert @temp2 select 479,'10100100','free'
insert @temp2 select 480,'10100100','free'
insert @temp2 select 481,'10100101','free'
insert @temp2 select 485,'10100100','free'
select cola,colb,colc
from
(
select v.*,
count(v.cola) over (partition by t.cola) AS cnt
from
(
select t.cola,colb,colc
from @temp2 t
where colb & 3=0
AND colc='free'
)t
cross join(select 0 union all
select 1 union all
select 2 union all
select 3)u(x)
left join @temp2 v
on v.cola = t.cola + x
)t
where cnt=4
No comments:
Post a Comment