473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to average 3 last records?

2 New Member
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
Feb 27 '07 #1
4 5119
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT Avg([FieldName)
  2. FROM (SELECT TOP 3 FieldName
  3. FROM TableName
  4. ORDER BY FieldName DESC);
  5.  
Feb 27 '07 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT Avg([FieldName)
  2. FROM (SELECT TOP 3 FieldName
  3. FROM TableName
  4. ORDER BY FieldName DESC);
  5.  
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 :
Expand|Select|Wrap|Line Numbers
  1. Table Name=tblStudent
  2. Field; Type; IndexInfo
  3. StudentID; Autonumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. LastAttendance; Date/Time
Mar 2 '07 #3
Tomas
2 New Member
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 :
Expand|Select|Wrap|Line Numbers
  1. Table Name=tblStudent
  2. Field; Type; IndexInfo
  3. StudentID; Autonumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. 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.

Expand|Select|Wrap|Line Numbers
  1. Darbuot_ID    Laikotarp_ID    Priskaiciuota_VISO
  2. 3                  2007-01-01    1.200,00 Lt
  3. 3                  2007-02-01    1.133,33 Lt
  4. 3                  2007-03-01    1.200,00 Lt
  5. 3                  2007-04-01    1.090,91 Lt
  6. 4                  2007-01-01    818,18 Lt
  7. 4                  2007-02-01    900,00 Lt
  8. 4                  2007-03-01    900,00 Lt
  9. 4                  2007-04-01    900,00 Lt
  10. 5                  2007-01-01    1.472,73 Lt
  11. 5                  2007-02-01    1.800,00 Lt
  12. 5                  2007-03-01    1.714,29 Lt
  13. 5                  2007-04-01    1.800,00 Lt
  14. 6                  2007-01-01    480,00 Lt
  15. 6                  2007-02-01    600,00 Lt
  16. 6                  2007-03-01    568,00 Lt
  17. 6                  2007-04-01    648,00 Lt
  18. 7                  2007-01-01    1.500,00 Lt
  19. 7                  2007-02-01    1.166,67 Lt
  20. 7                  2007-03-01    1.500,00 Lt
  21. 7                  2007-04-01    1.500,00 Lt
  22. 8                  2007-01-01    3.000,00 Lt
  23. 8                  2007-02-01    3.000,00 Lt
  24. 8                  2007-03-01    3.000,00 Lt
  25. 8                  2007-04-01    2.863,64 Lt
Mar 12 '07 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Try :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT P.Darbuot_ID,
  2.                 (SELECT TOP 3 Avg(Priskaiciuota_VISO) AS AvgTop3
  3.                  FROM Qry_priskaiciuota
  4.                  WHERE Qry_priskaiciuota.Darbuot_ID=P.Darbuot_ID
  5.                  ORDER BY Laikotarp_ID DESC).AvgTop3
  6. FROM Qry_priskaiciuota AS P
Mar 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2882
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...
2
13585
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...
1
1844
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,...
1
1921
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)...
4
3569
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...
1
2112
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...
2
13537
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...
1
7581
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...
8
7789
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
0
7120
marktang
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,...
0
6991
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...
0
7160
Oralloy
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,...
0
7373
tracyyun
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...
0
4583
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...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
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 ...
0
286
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.