Say I have a table with two columns that matter to this example,
[PointNumber] and [SurveyDate]. And here is an example of what the rows
currently look like:
[PointNumber], [SurveyDate]
1,6/27/2001
1,6/27/2001
1,5/31/2001
2,6/27/2001
2,6/30/2001
2,5/31/2001
I want a query that will return PointNumber and the number of surveys (ie.
how many different dates are in the table for each point). For the example
above, the query should output:
[PointNumber], [NumberOfSurveys]
1,2
2,3
I'd appreaciate any assistance. This seems like it would be simple but I
don't know how to do it. 8 2735
first make a query that returns unique pointnumber, surveydate combinations
(the 'unique values' query property will turn on 'select distinct')
then using that query, make a query that groups by pointnumber and counts
surveydate.
"DH" <dana_hartley@(remove)hotmail.com> wrote in message
news:vn************@corp.supernews.com... Say I have a table with two columns that matter to this example, [PointNumber] and [SurveyDate]. And here is an example of what the rows currently look like:
[PointNumber], [SurveyDate] 1,6/27/2001 1,6/27/2001 1,5/31/2001 2,6/27/2001 2,6/30/2001 2,5/31/2001
I want a query that will return PointNumber and the number of surveys (ie. how many different dates are in the table for each point). For the example above, the query should output:
[PointNumber], [NumberOfSurveys] 1,2 2,3
I'd appreaciate any assistance. This seems like it would be simple but I don't know how to do it.
ONE query is all you need
Select PointNumber, Count(*) from
YourTable
group by PointNumber
"dogwalker" <d@g.com> wrote in message
news:30******************@news20.bellglobal.com... first make a query that returns unique pointnumber, surveydate
combinations (the 'unique values' query property will turn on 'select distinct') then using that query, make a query that groups by pointnumber and counts surveydate.
"DH" <dana_hartley@(remove)hotmail.com> wrote in message news:vn************@corp.supernews.com... Say I have a table with two columns that matter to this example, [PointNumber] and [SurveyDate]. And here is an example of what the rows currently look like:
[PointNumber], [SurveyDate] 1,6/27/2001 1,6/27/2001 1,5/31/2001 2,6/27/2001 2,6/30/2001 2,5/31/2001
I want a query that will return PointNumber and the number of surveys
(ie. how many different dates are in the table for each point). For the
example above, the query should output:
[PointNumber], [NumberOfSurveys] 1,2 2,3
I'd appreaciate any assistance. This seems like it would be simple but I don't know how to do it.
I don't think so. You'll see she has 2 identical dates for PointNumber 1.
But she wants unique dates.
I think it does need another query. I tried to do it in one query but
couldn't find a way.
Mike
"HSalim" <On******************@msn.com> wrote in message
news:6X*******************@nwrdny01.gnilink.net... ONE query is all you need
Select PointNumber, Count(*) from YourTable group by PointNumber
"dogwalker" <d@g.com> wrote in message news:30******************@news20.bellglobal.com... first make a query that returns unique pointnumber, surveydate combinations (the 'unique values' query property will turn on 'select distinct') then using that query, make a query that groups by pointnumber and
counts surveydate.
"DH" <dana_hartley@(remove)hotmail.com> wrote in message news:vn************@corp.supernews.com... Say I have a table with two columns that matter to this example, [PointNumber] and [SurveyDate]. And here is an example of what the
rows currently look like:
[PointNumber], [SurveyDate] 1,6/27/2001 1,6/27/2001 1,5/31/2001 2,6/27/2001 2,6/30/2001 2,5/31/2001
I want a query that will return PointNumber and the number of surveys (ie. how many different dates are in the table for each point). For the example above, the query should output:
[PointNumber], [NumberOfSurveys] 1,2 2,3
I'd appreaciate any assistance. This seems like it would be simple but
I don't know how to do it.
Think again.
The requirement was:
the query should output:
[PointNumber], [NumberOfSurveys]
1,2
2,3
This is fulfilled by the query I posted.
If you want to count the number of surveys by points and dates use
Select PointNumber, SurveyDate, Count(*) as NumberOfSurveys
from YourTable
group by PointNumber, SurveyDate
HS
"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f***********************@pubnews.gradwell.ne t... I don't think so. You'll see she has 2 identical dates for PointNumber 1. But she wants unique dates.
I think it does need another query. I tried to do it in one query but couldn't find a way.
Mike
"HSalim" <On******************@msn.com> wrote in message news:6X*******************@nwrdny01.gnilink.net... ONE query is all you need
Select PointNumber, Count(*) from YourTable group by PointNumber
"dogwalker" <d@g.com> wrote in message news:30******************@news20.bellglobal.com... first make a query that returns unique pointnumber, surveydate combinations (the 'unique values' query property will turn on 'select distinct') then using that query, make a query that groups by pointnumber and counts surveydate.
"DH" <dana_hartley@(remove)hotmail.com> wrote in message news:vn************@corp.supernews.com... > Say I have a table with two columns that matter to this example, > [PointNumber] and [SurveyDate]. And here is an example of what the rows > currently look like: > > [PointNumber], [SurveyDate] > 1,6/27/2001 > 1,6/27/2001 > 1,5/31/2001 > 2,6/27/2001 > 2,6/30/2001 > 2,5/31/2001 > > I want a query that will return PointNumber and the number of
surveys (ie. > how many different dates are in the table for each point). For the example > above, the query should output: > > [PointNumber], [NumberOfSurveys] > 1,2 > 2,3 > > I'd appreaciate any assistance. This seems like it would be simple
but I > don't know how to do it. > > >
"HSalim" <On******************@msn.com> wrote in message
news:Il*******************@nwrdny01.gnilink.net... Think again.
The requirement was: the query should output: [PointNumber], [NumberOfSurveys] 1,2 2,3
Well, I just ran your query, with a table of the data that Dana supplied.
And I got:
1,3
2,3
So what am I doing wrong?
Did you get a different result when you ran your query against the sample
data?
Mike
Mike,
I am so sorry. I feel like such a fool.
I was so cock sure of myself that I did not read what you wrote.
You were ofcourse right. The resuts in my query does not match the desired
output.
The correct answer is
SELECT S.PointNumber, count(S.SurveyDate) as SurveyCount
FROM [Select Distinct PointNumber, SurveyDate from surveys]. as S
GROUP BY S.PointNumber;
which is essentially using a subquery that first returns distinct values
HS
"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f***********************@pubnews.gradwell.ne t... "HSalim" <On******************@msn.com> wrote in message news:Il*******************@nwrdny01.gnilink.net... Think again.
The requirement was: the query should output: [PointNumber], [NumberOfSurveys] 1,2 2,3
Well, I just ran your query, with a table of the data that Dana supplied. And I got:
1,3 2,3
So what am I doing wrong?
Did you get a different result when you ran your query against the sample data?
Mike
"HSalim" <On******************@msn.com> wrote in message
news:kv******************@nwrdny02.gnilink.net... Mike, I am so sorry. I feel like such a fool. I was so cock sure of myself that I did not read what you wrote. You were ofcourse right. The resuts in my query does not match the
desired output.
No need to apologise. It's easy to misread things.
The correct answer is SELECT S.PointNumber, count(S.SurveyDate) as SurveyCount FROM [Select Distinct PointNumber, SurveyDate from surveys]. as S GROUP BY S.PointNumber;
Why couldn't I get that! I knew there was a simple single query answer to
this. And I knew it was something to do with DISTINCT. I'll get it next time
one of these comes up.
Cheers, Mike
Mike,
Thanks for letting me off the hook so gracefully.
FYI: There is a way to do this in one query - i.e. without requiring a
subquery,
if you use ANSI SQL 92 Syntax. - unfortunately,
a. due to a known problem in Access, you will get an error.
b. it is a database wide option, so you may not want to choose this option.
Anyway, the single query syntax is simply
SELECT surveys.PointNumber,Count(DISTINCT surveys.SurveyDate) AS
CountOfSurveyDate
FROM surveys GROUP BY surveys.PointNumber;
You may find it useful when microsoft gets around to fixing the problem.
see http://support.microsoft.com/default...roduct=acc2002
HS
"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f***********************@pubnews.gradwell.ne t... "HSalim" <On******************@msn.com> wrote in message news:kv******************@nwrdny02.gnilink.net... Mike, I am so sorry. I feel like such a fool. I was so cock sure of myself that I did not read what you wrote. You were ofcourse right. The resuts in my query does not match the desired output.
No need to apologise. It's easy to misread things.
The correct answer is SELECT S.PointNumber, count(S.SurveyDate) as SurveyCount FROM [Select Distinct PointNumber, SurveyDate from surveys]. as S GROUP BY S.PointNumber;
Why couldn't I get that! I knew there was a simple single query answer to this. And I knew it was something to do with DISTINCT. I'll get it next
time one of these comes up.
Cheers, Mike
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cwhite |
last post by:
Hi
I have another drop list question.
I have a table like this:
computer dell
computer ibm
computer hp
|
by: terence.parker |
last post by:
I am often faced with the dilemma of whether to use a JOIN query across
three tables in order to grab a bunch of results - or whether to create
another table to represent what I want. The latter is...
|
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data...
|
by: Wayne Aprato |
last post by:
I posted this yesterday and it seems like a moderator has thrown it in
another thread. This is a totally different question to the one asked
in that thread, so I'm posting it again. It is not a...
|
by: meganrobertson22 |
last post by:
hi everybody-
what is the best way to add data from one form to another?
i have 2 tables: person and contract. here are some of the fields.
table: person
personid (autonumber and primary...
|
by: hmiller |
last post by:
I'm sorry to populate the server with yet another question about
linking multiple tables and queries, howerver I have not been able to
find the right criteria.
My problem.
I am trying to...
|
by: cor |
last post by:
In Access(97) I am able to have a cell to be a hyperlink referencing a spreadsheet,
a cell, a column or a database's table or query. When I click on it It opens
on such reference program. The...
|
by: Dorish3 |
last post by:
I want to apologize ahead of time for being a novice with MS Access
and VBA. I desperately need help with 2 queries that I am trying to
put together. I want to thank anyone that can help me out...
|
by: Doris |
last post by:
It does not look like my message is posting....if this is a 2nd or 3rd
message, please forgive me as I really don't know how this site works.
I want to apologize ahead of time for being a novice...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |