locations
---------
contract_id INT
order_position INT # I want to find any bad data in this column
我想給定contract_id
內找到任何重複order_position
秒。
因此,例如,像如果兩個locations
行過的「24845」一個contract_id
兩者具有「3」的order_position
任何情況。
我正在使用MySQL 5.1。
locations
---------
contract_id INT
order_position INT # I want to find any bad data in this column
我想給定contract_id
內找到任何重複order_position
秒。
因此,例如,像如果兩個locations
行過的「24845」一個contract_id
兩者具有「3」的order_position
任何情況。
我正在使用MySQL 5.1。
HAVING子句可以告訴你在哪裏重複存在的實例:
SELECT *
FROM locations
GROUP BY contract_id, order_position
HAVING COUNT(*) > 1
select contract_id, order_position
from locations
group by contract_id, order_position
having count(*) > 1
SELECT contract_id, order_position, count(*)
FROM locations
GROUP BY contract_id, order_position
HAVING count(*) > 1
SELECT contract_id, order_position, COUNT(order_position) AS cnt
FROM locations
GROUP BY contract_id, order_position
HAVING cnt > 1;
Why COUNT(column)
is usually better than COUNT(*)
(好吧,這只是區分我的答案:d)