Mysql查詢重複記錄

第一步 使用group by 和 having cout 查找重複字段
SELECT t1.`order_book_id` FROM `quant_stock_info` t1 GROUP BY t1.`order_book_id` HAVING COUNT(t1.`order_book_id`)>1 
第二步 使用IN查找
SELECT * FROM `quant_stock_info` t0 
WHERE t0.`order_book_id` 
IN (
	SELECT t1.`order_book_id` FROM `quant_stock_info` t1 
	GROUP BY t1.`order_book_id` HAVING COUNT(t1.`order_book_id`)>1
) 
ORDER BY t0.`order_book_id`
相關文章
相關標籤/搜索