需要MS Access查询

问题描述 投票:-3回答:4

我在表“ customer”中有数据,例如

ID    NAME    CITY
11    John     A
12    Peter    B
13    Robin    A
14    Steve    C
15    Methew   D
16    Matt     C
17    Nancy    C
18    Oliver   D

我希望查询仅显示同一城市中每2个客户的数据。

输出应为,


ID    NAME    CITY
11    John     A
13    Robin    A
15    Methew   D
18    Oliver   D
sql ms-access criteria access ms-access-2016
4个回答
-1
投票
select a.ID1,a.Name1,a.City,b.cnt_of_customers from Customers as a ,( SELECT City ,count(*) as cnt_of_customers FROM Customers GROUP BY City HAVING count(*)=2) as b where a.city=b.city

enter image description here


-2
投票
SELECT a.Id ,a.Name ,a.City FROM Customer AS a INNER JOIN Customer AS b ON a.City = b.City

-2
投票
select * from Customer as z where ID IN ( select top 2 ID from Customer as c where c.city = z.city) order by city

enter image description here


-4
投票
© www.soinside.com 2019 - 2024. All rights reserved.