0

桌子:

locations
---------
contract_id INT
order_position INT   # I want to find any bad data in this column

我想order_position在给定的contract_id.

因此,例如任何情况,例如如果两locations行的 acontract_id“24845”,并且两者的 aorder_position“3”。

我正在使用 MySQL 5.1。

4

4 回答 4

3
select contract_id, order_position
from locations
group by contract_id, order_position
having count(*) > 1
于 2013-06-12T21:05:06.947 回答
1
SELECT contract_id, order_position, count(*)
FROM locations
GROUP BY contract_id, order_position
HAVING count(*) > 1
于 2013-06-12T21:05:33.767 回答
1

HAVING 子句可以显示存在重复项的实例:

SELECT *
FROM locations
GROUP BY contract_id, order_position
HAVING COUNT(*) > 1
于 2013-06-12T21:05:34.143 回答
1
SELECT contract_id, order_position, COUNT(order_position) AS cnt
FROM locations
GROUP BY contract_id, order_position
HAVING cnt > 1;

为什么COUNT(column)通常比COUNT(*)(好吧,这只是为了区分我的答案:D)

于 2013-06-12T21:06:24.863 回答