简体   繁体   中英

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. Here is an example of the existing table, let's call it 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:

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. For example, C1 represents companies such as KFC and McDonalds. C2 represents work dates. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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