1. 程式人生 > >sql查詢兩條以上的資料 having

sql查詢兩條以上的資料 having

select f1,f2,...,fn
from table
group by f1,f2,...,fn
having count(1)>1 查出存在相同的f1,f2,..,fn
想查找出記錄則
select t1.* from table t1
join (select f1,f2,...,fn from table group by f1,f2,...,fn having count(1)>1) t2
on t1.f1=t2.f1 and t1.f2=t2.f2 and ... and t1.fn=t2.fn