select id , a,b,c from
(
select * , px = (select count(1) from tiao1 where a = t.a and b=t.b and c=t.c and id = t.id - 1) + 1 from biao1 t
) m
where px <= 4
(
select * , px = (select count(1) from tiao1 where a = t.a and b=t.b and c=t.c and id = t.id - 1) + 1 from biao1 t
) m
where px <= 4
WHERE (SELECT COUNT(*) FROM TB WHERE A=A.A AND ID>=A.ID)<=4
insert into tb values(1 , 11 , 'TT' , 'EE')
insert into tb values(2 , 22 , 'II' , 'KK')
insert into tb values(3 , 11 , 'OO' , '55')
insert into tb values(4 , 33 , '56' , '35')
insert into tb values(5 , 33 , '56' , '35')
insert into tb values(6 , 33 , '56' , '35')
insert into tb values(7 , 33 , '56' , '35')
insert into tb values(8 , 33 , '56' , '35')
insert into tb values(9 , 33 , '56' , '35')
insert into tb values(10, 22 , '89' , 'FD')
insert into tb values(11, 22 , '89' , 'FD')
insert into tb values(12, 22 , '89' , 'FD')
insert into tb values(13, 22 , '89' , 'FD')
goselect id , a,b,c from
(
select * , px = (select count(1) from tb where a = t.a and b=t.b and c=t.c and id < t.id) + 1 from tb t
) m
where px <= 4
order by iddrop table tb/*
id a b c
----------- ----------- ---------- ----------
1 11 TT EE
2 22 II KK
3 11 OO 55
4 33 56 35
5 33 56 35
6 33 56 35
7 33 56 35
10 22 89 FD
11 22 89 FD
12 22 89 FD
13 22 89 FD(所影响的行数为 11 行)
*/