2014-06-23 59 views
1

顯示重複行我有這個表在訪問

MEN

id | Qty | Place 
======================== 
111 | 10  | 55 
111 | 20  | 66 
111 | 10  | 77 
222 | 40  | 11 
333 | 50  | 11 
111 | 10  | 22 
222 | 44  | 33 
222 | 40  | 44 
333 | 15  | 55 

我需要顯示所有記錄該ID = ID和數量=數量是這樣的:

id | Qty | Place 
===================== 
111 | 10 | 55 
111 | 10 | 77 
111 | 10 | 22 
222 | 40 | 11 
222 | 40 | 44 

回答

2

試試這個

SELECT T.ID,T.Qty 
FROM Table1 T 
GROUP BY T.ID,T.Qty 
HAVING (((Count(*))>1)); 

使用下面的查詢來獲得全套的記錄的細節:

SELECT R.Id, R.Qty, R.Place 
FROM Table1 R INNER JOIN 
(
SELECT T.Id, T.Qty 
FROM Table1 T 
GROUP BY T.Id, T.Qty 
HAVING (((Count(*))>1)) 
)AS JR ON R.Qty = JR.Qty AND R.Id = JR.Id 
2

你可以做這樣的事情:

SELECT MEN.Id, MEN.Qty, MEN.Place 
FROM MEN INNER JOIN 
(SELECT MEN.Id, MEN.Qty 
FROM MEN 
GROUP BY MEN.Id, MEN.Qty 
HAVING (((Count(*))>1))) AS a 
ON (MEN.Qty = a.Qty) AND (MEN.Id = a.Id) 
ORDER BY MEN.Id, MEN.Qty; 

創建內部查詢發現那裏有編號的多個實例然後將其加回到原始表格以獲取位置值。