简体   繁体   English

MS-Access:查询现有表中的数据

[英]MS-Access: Querying data in an existing table

I'm trying to create a query in MS-Access that will lookup an exiting table and produce a particular result. 我正在尝试在MS-Access中创建一个查询,该查询将查找现有表并产生特定结果。 Here is an example of the existing table, let's call it tblA: 这是现有表的示例,我们称其为tblA:

C1  C2  
1   Balloon
2   Tree
1   Bike
1   Tree
2   Balloon
2   Kite
1   Clown
1   Balloon 

The query I'm trying to write will look at tblA, view column C2 and produce a result that will show values greater than 1. Here is my desired result of the query: 我尝试编写的查询将查看tblA,查看列C2并产生一个结果,该结果将显示大于1的值。这是我希望查询的结果:

C2
Balloon
Tree

Explanation of the expected output : What I'm trying to accomplish is if values in C1 share the same value in C2, I wan't the query to display the shared C2 value. 预期输出的说明 :我要完成的工作是,如果C1中的值在C2中共享相同的值,那么我将不查询以显示共享的C2值。 For example, C1 represents companies such as KFC and McDonalds. 例如,C1代表肯德基和麦当劳等公司。 C2 represents work dates. C2代表工作日期。 If KFC and McDonalds share the same work date (eg Dec 1, 2017), I want the query to display only the work date, ie Dec 1, 2017. 如果肯德基和麦当劳共享相同的工作日期(例如,2017年12月1日),我希望查询仅显示工作日期,即2017年12月1日。

I'm a rookie at this stuff, so any help is greatly appreciated. 我是这个菜鸟的新手,因此非常感谢您的帮助。

Use the following: 使用以下内容:

SELECT Count(tblA.C1) AS CountOfC1, tblA.C2
FROM tblA
GROUP BY tblA.C2
HAVING (((Count(tblA.C1))>1));

You can try this : 您可以尝试以下方法:

select distinct A.C2 from tblA A
join tblA B on A.C2 = B.C2 and A.C1 <> B.C1

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

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