sql查詢某字段的相同值:
SELECT * FROM table WHERE col in (SELECT col FROM table GROUP BY col HAVING COUNT (col) >1);
順帶說一下where和having:
select * from table
where ···(只能對分組前的屬性進行篩選)
group by ···(按某個字段分組)
having ···(只能對分組后的每個組的整體屬性進行篩選,用聚合函數體現)
--不使用group by就默認表的整體為一組
實例:
查詢出重復記錄
select * from 數據表 WHERE 重復記錄字段 in ( select 重復記錄字段 from 數據表 group by 重復記錄字段 having count(重復記錄字段)>1)