declare @ttable(IDint,EmpID nvarchar(4),[Days] int)
insert into @t
select 1,'0001',10 UNION ALL
select 2,'0001',10 UNION ALL
select 3, '0002', 15 UNION ALL
select 4, '0002', 15UNION ALL
select 5,'0002', 15 UNION ALL
select 6, '0002', 15 UNION ALL
select 7,'0002', 15 UNION ALL
select 8, '0002', 15 UNION ALL
select 9,'0002', 15
UNION ALL
select 10, '0003', 10UNION ALL
select 11,'0003', 11
UNION ALL
select 12, '0003', 12
UNION ALL
select 13,'0003', 12 UNION ALL
select 14, '0003', 12UNION ALL
select 15,'0003', 12 UNION ALL
select 16, '0003', 12
UNION ALL
select 17,'0003 ',12 UNION ALL
select 18,'0003', 12
SELECT T.ID, T.EmpID, S.[Days] FROM
@t AS T
JOIN
(
SELECT EmpID, [Days] FROM
@t
GROUP BY EmpID, [Days]
HAVING COUNT(*) >= 7
) AS S
ON
T.EmpID = S.EmpID
AND T.[Days] = S.[Days]
/*
(18 row(s) affected)
ID
EmpID Days
----------- ----- -----------
3 000215
4 000215
5 000215
6 000215
7 000215
8 000215
9 000215
12
000312
13
000312
14
000312
15
000312
16
000312
17
000312
18
000312
(14 row(s) affected)
*/
|