select B.* from xhb_ceshi B inner join (select distinct id1,id2,id3,userid from xhb_ceshi group by id1,id2,id3,userid having count(*)<3) C
on b.id1=c.id1 and b.id2 =c.id2 and b.id3=c.id3 and c.userid =b.userid
select a.* from xhb_ceshi a
, (select id1 ,id2, id3, userid, count( id5) as id5 from xhb_ceshi
group by id1 , id2 , id3 , userid
having count( id5)<3) b
where a.id1=b.id1
and a.id2=b.id2
and a.id3=b.id3
and a.userid=b.userid
这个语句在ORACLE下执行没问题,奇怪的是在SYBASE下报错了,语法错误在'('
这样实现:
select a.id1,a.id2,a.id3,a.userid,a.id5
from A,
(
select count(id1||id2||id3||userid) as count,id1,id2,id3,userid
from A
group by id1,id2,id3
where count(id1||id2||id3||userid) < 3
) B
where a.id1 = b.id1
and a.id2 = b.id2
and a.id3 = b.id3
and a.userid = b.userid
insert into xhb_ceshi
select '2','100','4','15','12' from dual
union
select '2','100','4','15','13' from dual
union
select '2','100','4','15','14' from dual
union
select '2','101','4','15','12' from dual
union
select '2','102','4','15','13' from dual
union
select '2','101','4','15','14' from dual
;
commit;
select a.* from xhb_ceshi a
, (select id1 ,id2, id3, userid, count( id5) as id5 from xhb_ceshi
group by id1 , id2 , id3 , userid
having count( id5)<3) b
where a.id1=b.id1
and a.id2=b.id2
and a.id3=b.id3
and a.userid=b.userid
;
select a.* from xhb_ceshi a
, (select id1 ,id2, id3, userid, count(id5) as id5 from xhb_ceshi
group by id1 , id2 , id3 , userid
having count(xhb_ceshi.id5)<3) b
where a.id1=b.id1
and a.id2=b.id2
and a.id3=b.id3
and a.userid=b.userid
;