A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

subquery



 
 
Thread Tools Display Modes
  #1  
Old December 22nd, 2009, 10:41 PM posted to microsoft.public.access.queries
Kou Vang
external usenet poster
 
Posts: 16
Default subquery

How can I write a subquery within a query from:

Lake, Site, PersonID
01, 101, 0001
01, 101, 0001
01, 101, 0001
01, 101, 0002
01, 101, 0002
01, 101, 0003
01, 102, 0001
01, 102, 0001

To get: the total visits by site and total by person.

Thanks,

Kou
  #2  
Old December 22nd, 2009, 11:14 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default subquery

Try this --
SELECT Site, (SELECT Count([YY].[Site] FROM YourTable
AS [XX]) AS Site_Visits, PersonID, (SELECT Count([YY].[PersonID] FROM
YourTable
AS [YY]) AS Person_Visits
FROM YourTable;

--
Build a little, test a little.


"Kou Vang" wrote:

How can I write a subquery within a query from:

Lake, Site, PersonID
01, 101, 0001
01, 101, 0001
01, 101, 0001
01, 101, 0002
01, 101, 0002
01, 101, 0003
01, 102, 0001
01, 102, 0001

To get: the total visits by site and total by person.

Thanks,

Kou

  #3  
Old December 23rd, 2009, 02:22 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default subquery

It is a bit unclear as to what you want. Perhaps the following will give you
an idea that you can use to solve your problem.

SELECT DISTINCT Lake, Site, PersonID
, (SELECT Count(*) FROM TheTable as Temp WHERE Temp.Lake = TheTable.Lake and
Temp.Site = TheTable.Site) as SiteCount
, (SELECT Count(*) FROM TheTable as Temp WHERE Temp.Lake = TheTable.Lake and
Temp.PersonID= TheTable.PersonID) as PersonCount
FROM TheTable

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Kou Vang wrote:
How can I write a subquery within a query from:

Lake, Site, PersonID
01, 101, 0001
01, 101, 0001
01, 101, 0001
01, 101, 0002
01, 101, 0002
01, 101, 0003
01, 102, 0001
01, 102, 0001

To get: the total visits by site and total by person.

Thanks,

Kou

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.