Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SELECT T2.ITEM_ID AS item_ITEM_ID FROM types T JOIN items T2 ON T.ITEM_ID = T2.ITEM_PARENT_ID WHERE T.ITEM_TYPE = 'I' AND T2.ITEM_TYPE = 'I'
此查询从 T2 返回具有重复 T2.ITEM_PARENT_ID 的行。我将如何指定此查询以仅返回具有唯一 T2.ITEM_PARENT_IDs 的行?
计算重复次数并在大于 1 时过滤掉。
SELECT T2.ITEM_ID AS item_ITEM_ID, COUNT(*) dups FROM types T JOIN items T2 ON T.ITEM_ID = T2.ITEM_PARENT_ID WHERE T.ITEM_TYPE = 'I' AND T2.ITEM_TYPE = 'I' GROUP BY item_ITEM_ID HAVING dups = 1
演示