I'm creating MS Access database and I need to have in query an average of 3 last records.
How to do it?
Maybe here is some function or sql expresion?
Thanks
4 5119 MMcCarthy 14,534
Recognized Expert Moderator MVP
Try this ... -
SELECT Avg([FieldName)
-
FROM (SELECT TOP 3 FieldName
-
FROM TableName
-
ORDER BY FieldName DESC);
-
NeoPa 32,556
Recognized Expert Moderator MVP
Try this ... -
SELECT Avg([FieldName)
-
FROM (SELECT TOP 3 FieldName
-
FROM TableName
-
ORDER BY FieldName DESC);
-
Other than the problem of finding the last 3 records rather than the highest 3 by fieldname, this is a perfect example of how to do it.
Tomas, you need to provide more information in the question as to how the table is structured and how the order of the records may be determined.
Please post the table MetaData in the following format : - Table Name=tblStudent
- Field; Type; IndexInfo
-
StudentID; Autonumber; PK
-
Family; String; FK
-
Name; String
-
University; String; FK
-
Mark; Numeric
-
LastAttendance; Date/Time
Other than the problem of finding the last 3 records rather than the highest 3 by fieldname, this is a perfect example of how to do it.
Tomas, you need to provide more information in the question as to how the table is structured and how the order of the records may be determined.
Please post the table MetaData in the following format : - Table Name=tblStudent
- Field; Type; IndexInfo
-
StudentID; Autonumber; PK
-
Family; String; FK
-
Name; String
-
University; String; FK
-
Mark; Numeric
-
LastAttendance; Date/Time
Here is my data: Query Name = Qry_priskaiciuota
Field; Type; Index/Info
Darbuot_ID; Numeric
Laikotarp_ID; Date/Time
Priskaiciuota_VISO; Currency
I need the Average of Priskaiciuota_VISO by 3 last Laikotarp_ID records for Darbuot_ID. - Darbuot_ID Laikotarp_ID Priskaiciuota_VISO
-
3 2007-01-01 1.200,00 Lt
-
3 2007-02-01 1.133,33 Lt
-
3 2007-03-01 1.200,00 Lt
- 3 2007-04-01 1.090,91 Lt
-
4 2007-01-01 818,18 Lt
-
4 2007-02-01 900,00 Lt
-
4 2007-03-01 900,00 Lt
- 4 2007-04-01 900,00 Lt
-
5 2007-01-01 1.472,73 Lt
-
5 2007-02-01 1.800,00 Lt
-
5 2007-03-01 1.714,29 Lt
- 5 2007-04-01 1.800,00 Lt
-
6 2007-01-01 480,00 Lt
-
6 2007-02-01 600,00 Lt
-
6 2007-03-01 568,00 Lt
- 6 2007-04-01 648,00 Lt
-
7 2007-01-01 1.500,00 Lt
-
7 2007-02-01 1.166,67 Lt
-
7 2007-03-01 1.500,00 Lt
- 7 2007-04-01 1.500,00 Lt
-
8 2007-01-01 3.000,00 Lt
-
8 2007-02-01 3.000,00 Lt
-
8 2007-03-01 3.000,00 Lt
- 8 2007-04-01 2.863,64 Lt
NeoPa 32,556
Recognized Expert Moderator MVP
Try : - SELECT DISTINCT P.Darbuot_ID,
-
(SELECT TOP 3 Avg(Priskaiciuota_VISO) AS AvgTop3
-
FROM Qry_priskaiciuota
-
WHERE Qry_priskaiciuota.Darbuot_ID=P.Darbuot_ID
-
ORDER BY Laikotarp_ID DESC).AvgTop3
-
FROM Qry_priskaiciuota AS P
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Greg |
last post by:
I am trying to get the average amount current, over30, over 60, etc..... for
my report. I have the total of the balance, total of Currnet, Over 30, etc.
but unable to get the Average percent of...
|
by: Wayne Aprato |
last post by:
I've read most, if not all, of the posts on moving average and still
can't find a simple solution to my problem (if a simple solution
exists!) I have a table with 2 fields: Hours and Injuries. I...
|
by: edhead |
last post by:
Access newbie here, I am trying to figure out how to set up a query
that will return an average from multiple records all created on the
same date. Table has the following fields date, weight1,...
|
by: Joost |
last post by:
Who can help me,
I have a table which contain an artikels and a prices.
What i want is to the following
1) The average price from the last 7 records.
2) The average from the last 14 records
3)...
|
by: Scott |
last post by:
In order to give a meaning average value and minimum and maximum values, I
would like to have a formula for a group of data after taking out those
extremes. Can someone share your way to...
| |
by: Theadmin77 |
last post by:
Well ...this is a real challenge .....i got everything else working OK...but ...
I have to get the average and maximum value out of a group of people thru two functions .I have problems passing...
|
by: chrisale |
last post by:
Hi All,
I've been racking my brain trying to figure out some sort of Sub-Select
mySQL statement that will create a result with multiple rows of
averaged values over a years time.
What I have...
|
by: Michel |
last post by:
Hello,
I need to calculate moving averages of weekly data during the last
year.
After some search, I believe that the best approach will be to get a
dataset from the SQL Server database, browse...
|
by: charli |
last post by:
I have a table of Waste IDs, with a relationship with a second table of Waste Weights:
WasteIDs
id name
1. Paper
2. Cardboard
3. Cans
WasteWeights:
Id date kg
1. 1/1/09 12
1. 1/2/09 24
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |