在访问中显示重复的行

时间:2014-06-23 10:44:07

标签: sql ms-access

我有这张桌子

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和Qty = Qty的记录,如下所示:

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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;

创建内部查询以查找Id的多个实例的位置,然后将其连接回原始表以获取Place值。