繁体   English   中英

需要MS Access查询[保留]

[英]MS Access query required [on hold]

我在“ 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

以下查询执行此操作

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

在此处输入图片说明

尝试这个

select * from Customer where City IN (
 select  city  from Customer as c
  group by city having Count(City) = 2)

请尝试此查询,如果您有任何问题,请告诉我们。

SELECT a.Id
    ,a.Name
    ,a.City
FROM Customer AS a
INNER JOIN Customer AS b ON a.City = b.City

我不知道如何在这里以表格形式写入数据。 如果有人,请以表格格式编辑数据。 ID NAME和CITY是标题。 A,B,C,D是城市名称。 11,12,13,14,14,15,16,17,18是ID

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM