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  

Writing a query to get a sum of a group average



 
 
Thread Tools Display Modes
  #1  
Old February 6th, 2007, 05:50 PM posted to microsoft.public.access.queries
ktm400
external usenet poster
 
Posts: 9
Default Writing a query to get a sum of a group average

Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.

I'm quite new to queries so not sure how to write the query.

Thanks for any help
  #2  
Old February 6th, 2007, 06:03 PM posted to microsoft.public.access.queries
Jason Lepack
external usenet poster
 
Posts: 600
Default Writing a query to get a sum of a group average

On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.

I'm quite new to queries so not sure how to write the query.

Thanks for any help


This will calculate your daily total of hourly averages:

SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn

  #3  
Old February 6th, 2007, 07:35 PM posted to microsoft.public.access.queries
ktm400
external usenet poster
 
Posts: 9
Default Writing a query to get a sum of a group average

Thank you.
I ended up with this expression:

SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));

What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....


"Jason Lepack" wrote:

On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.

I'm quite new to queries so not sure how to write the query.

Thanks for any help


This will calculate your daily total of hourly averages:

SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn


  #4  
Old February 6th, 2007, 10:41 PM posted to microsoft.public.access.queries
Jason Lepack
external usenet poster
 
Posts: 600
Default Writing a query to get a sum of a group average

SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate

On Feb 6, 2:35 pm, ktm400 wrote:
Thank you.
I ended up with this expression:

SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));

What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....



"Jason Lepack" wrote:
On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.


I'm quite new to queries so not sure how to write the query.


Thanks for any help


This will calculate your daily total of hourly averages:


SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn- Hide quoted text -


- Show quoted text -



  #5  
Old February 7th, 2007, 05:30 PM posted to microsoft.public.access.queries
ktm400
external usenet poster
 
Posts: 9
Default Writing a query to get a sum of a group average

Thanks Jason.
When I run the query I get this message:

You tried to execute a query that does not include the specified expression
"hour(readingtime)" as part of an aggregate function. (Error 3122)


"Jason Lepack" wrote:

SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate

On Feb 6, 2:35 pm, ktm400 wrote:
Thank you.
I ended up with this expression:

SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));

What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....



"Jason Lepack" wrote:
On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.


I'm quite new to queries so not sure how to write the query.


Thanks for any help


This will calculate your daily total of hourly averages:


SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn- Hide quoted text -


- Show quoted text -




  #6  
Old February 7th, 2007, 06:55 PM posted to microsoft.public.access.queries
Jason Lepack
external usenet poster
 
Posts: 600
Default Writing a query to get a sum of a group average

On Feb 7, 12:30 pm, ktm400 wrote:
Thanks Jason.
When I run the query I get this message:

You tried to execute a query that does not include the specified expression
"hour(readingtime)" as part of an aggregate function. (Error 3122)



"Jason Lepack" wrote:
SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate


On Feb 6, 2:35 pm, ktm400 wrote:
Thank you.
I ended up with this expression:


SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));


What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....


"Jason Lepack" wrote:
On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.


I'm quite new to queries so not sure how to write the query.


Thanks for any help


This will calculate your daily total of hourly averages:


SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -


Copy your SQL from the Query and paste it here.

  #7  
Old February 7th, 2007, 07:09 PM posted to microsoft.public.access.queries
ktm400
external usenet poster
 
Posts: 9
Default Writing a query to get a sum of a group average

SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate


"Jason Lepack" wrote:

On Feb 7, 12:30 pm, ktm400 wrote:
Thanks Jason.
When I run the query I get this message:

You tried to execute a query that does not include the specified expression
"hour(readingtime)" as part of an aggregate function. (Error 3122)



"Jason Lepack" wrote:
SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate


On Feb 6, 2:35 pm, ktm400 wrote:
Thank you.
I ended up with this expression:


SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));


What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....


"Jason Lepack" wrote:
On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.


I'm quite new to queries so not sure how to write the query.


Thanks for any help


This will calculate your daily total of hourly averages:


SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -


Copy your SQL from the Query and paste it here.


  #8  
Old February 7th, 2007, 08:24 PM posted to microsoft.public.access.queries
ktm400
external usenet poster
 
Posts: 9
Default Writing a query to get a sum of a group average

Well - this works, but Iam not sure why.

SELECT sum(AvgOfCurrentSteamFlow)
FROM [SELECT dbo_Boiler_Steam_Production.ReadingDate AS Expr1,
Hour([ReadingTime]) AS Expr3,
Avg(dbo_Boiler_Steam_Production.CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM dbo_Boiler_Steam_Production
GROUP BY dbo_Boiler_Steam_Production.ReadingDate, Hour([ReadingTime])
HAVING (((Year([ReadingDate]))=[Select Year]))]. AS [%$##@_Alias];

What is the "AS [%$##@_Alias]" part?

"ktm400" wrote:

SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate


"Jason Lepack" wrote:

On Feb 7, 12:30 pm, ktm400 wrote:
Thanks Jason.
When I run the query I get this message:

You tried to execute a query that does not include the specified expression
"hour(readingtime)" as part of an aggregate function. (Error 3122)



"Jason Lepack" wrote:
SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate

On Feb 6, 2:35 pm, ktm400 wrote:
Thank you.
I ended up with this expression:

SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));

What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....

"Jason Lepack" wrote:
On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.

I'm quite new to queries so not sure how to write the query.

Thanks for any help

This will calculate your daily total of hourly averages:

SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


Copy your SQL from the Query and paste it here.


  #9  
Old February 7th, 2007, 08:36 PM posted to microsoft.public.access.queries
Jason Lepack
external usenet poster
 
Posts: 600
Default Writing a query to get a sum of a group average

I had the alias for the Hour(ReadingTime) in the group by instead of
Hour(ReadingTime).

SELECT ReadingDate, Sum(AvgFlow) AS SumOfAvgFlow
FROM (SELECT ReadingDate, Hour(readingtime) AS ReadingHour,
Avg(CurrentSteamFlow) AS AvgFlow
FROM [Steam Production]
GROUP BY ReadingDate, Hour(readingtime)
HAVING Year([ReadingDate])=[Year]) AS A
GROUP BY ReadingDate;

Cheers,
Jason Lepack

On Feb 7, 2:09 pm, ktm400 wrote:
SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate



"Jason Lepack" wrote:
On Feb 7, 12:30 pm, ktm400 wrote:
Thanks Jason.
When I run the query I get this message:


You tried to execute a query that does not include the specified expression
"hour(readingtime)" as part of an aggregate function. (Error 3122)


"Jason Lepack" wrote:
SELECT ReadingDate, sum(AvgOfCurrentSteamFlow)
FROM
(SELECT ReadingDate,
hour(readingtime) AS ReadingHour,
avg(CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY ReadingDate, ReadingHour
HAVING year(ReadingDate) = [Year])
GROUP BY ReadingDate


On Feb 6, 2:35 pm, ktm400 wrote:
Thank you.
I ended up with this expression:


SELECT [Steam Production].ReadingDate, Hour([readingtime]) AS ReadingHour,
Avg([Steam Production].CurrentSteamFlow) AS AvgOfCurrentSteamFlow
FROM [Steam Production]
GROUP BY [Steam Production].ReadingDate, Hour([readingtime])
HAVING (((Year([ReadingDate]))=[Year]));


What I need to do now is sum the AvgOfCurrentSteamFlow column.
I can't seem to figure it out without creating a seperate query.....


"Jason Lepack" wrote:
On Feb 6, 12:50 pm, ktm400 wrote:
Please help -
I have a table with 3 columns. One of the columns is date, one is time and
the last one is the value I want to average.
What I need to do is group the third column (my value) by hour and date
(there are 4 entries/hour) then average the 4 readings for the hour and then
add those averages together.


I'm quite new to queries so not sure how to write the query.


Thanks for any help


This will calculate your daily total of hourly averages:


SELECT dateColumn, sum(hourlyAverage)
FROM
(SELECT dateColumn,
hour(timeColumn) AS hourColumn,
avg(averageColumn) AS hourlyAverage
FROM yourTable
GROUP BY dateColumn, hourColumn)
GROUP BY dateColumn- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -


Copy your SQL from the Query and paste it here.- Hide quoted text -


- Show quoted text -



 




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 04:13 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.