473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need a query to return one date and the previous date only

Hi

I have a database which records students and their test scores. Each student could have between two and ten tests. The test are in one table and the students in another.

I want to create a query which will allow me to compare results between tests the student has taken. Unfortunately the database was set up with all the tests having the same name, so the only thing that varies between them is the date and the score.

I want to be able to set a parameter of say "tests in 2009" or "tests between x and y", and have the query return the score for the latest test in that year or period, AND the score for the test before (but not all the tests before!). I will then get the query to calculate the difference so I can measure progress.

I have constructed a query with the parameters but am only able to get it to give me a comparison between all of the tests. I thought about somehow getting a query to order the tests and only return the last two but not sure how to do this.

Any help would be greatly appreciated.

Thanks.
Dec 1 '10 #1
4 1346
ADezii
8,834 Expert 8TB
Tom, kindly post some more info, such as: Name of the Test Table with Field Names and Data Types, Name of the Student Table with Field Names and Data Types. I assume that the Tables are related, if so what are the Linking Field Names? Post some sample Data for a Student and what the results are that you would like to see, then we'll see what we can do.
Dec 1 '10 #2
Hi ADezii

The Student table is called 010t_children, important field names are child_id (an automatically generated unique number), first_name, last_name, dob (dd/mm/yyyy), start_date (dd/mm/yyyy). The Test table is called 020t_test, important field names are test_id (an automatically generated unique number), child_id (linking it to the 010t_children table), read_raw_score (a positive integer relating to their score on the test), read_age_years, read_age_months (these two give the reading age in years and months), spell_raw_score (a positive integer relating to their score on the test), spell_age_years, spell_age_months (again, these give spelling age in years and months), test_date (dd/mm/yyyy), test_type (there are three types of test, initial, progress and Exit - I can quite easily set it up to give me the the difference between two different tests, but the thing I want to be able to do is compare two "progress tests" based on dates, which is more difficult).

Sample data would be: Child_id: 1; first_name:John; last_name:smith; dob:12/10/1998; start date:01/10/2007. They may then have a number of tests such as:

test_id:1; test_type:initial test; test_date:01/10/2007; read_raw_score:20; read_age_years:5; read age months:11; spell_raw_score:15; spell_age_years:5; spell_age_months:8

test_id:47; test_type:progress test; test_date:01/2/2008; read_raw_score:25; read_age_years:6; read age months:5; spell_raw_score:20; spell_age_years:6; spell_age_months:2

test_id:76; test_type:progress test; test_date:12/6/2008; read_raw_score:30; read_age_years:6; read age months:9; spell_raw_score:29; spell_age_years:6; spell_age_months:11

test_id:82; test_type:exit test; test_date:12/6/2009; read_raw_score:35; read_age_years:7; read age months:9; spell_raw_score:37; spell_age_years:7; spell_age_months:11

Result I would like to see is a query which I can set the parameters for. So here for example I would want to put the parameter as "tests between 01/09/2007 and 31/08/2008". I then want the query to return and compare two tests, the latest one in this period and the one immediately before (note, the one before may not always be within the period defined in the parameter).

So here I would expect to see: Child_id:1; first_name:John; test_id:47; test_date:01/02/2008: read_raw_score:25; read_age_years:6; read age months:5; spell_raw_score:20; spell_age_years:6; spell_age_months:2; test_id:76; test_type:progress test; test_date:12/6/2008; read_raw_score:30; read_age_years:6; read age months:9; spell_raw_score:29; spell_age_years:6; spell_age_months:11; (and then some calculated fields, one to calculate the difference in time between the two tests and one to calculate the difference in reading ages between the tests) Date_difference_months:4; read_age_diff_months:4; spell_age_diff_moonths:9.

I hope this is clear. Please let me know if not or let me know if anything needs to be clarified or added.

Thanks,

Tom.
Dec 2 '10 #3
ADezii
8,834 Expert 8TB
Give me a little time to digest everything, and see what I can come up with.

Before I can proceed, something immediately jumps up at me:
I then want the query to return and compare two tests, the latest one in this period and the one immediately before (note, the one before may not always be within the period defined in the parameter).
Since the Date 'immediately before' may actually fall 'before' the Start Date Parameter, then this Start Date is actually irrelevant, and the Criteria should be:
Expand|Select|Wrap|Line Numbers
  1. <=[End Date]
If you specific Start and End Date Parameters in a Query, then any Dates prior to the Start Date will not be returned, and cannot be analyzed. The answer, as I see it, would be the Single Criteria in conjunction with a defined Sort Order on the Test Dates. If I am incorrect in any of these statements, please clarify. Thanks.
This Thread was quite a challenge, but I do believe that I have arrived at a workable solution which can easily be integrated into your existing Database Structure. Download the Attachment and look over it carefully. Should you have any questions, please post the relevant code, if any, along with as much detail as possible.
Dec 2 '10 #4
ADezii
8,834 Expert 8TB
This Thread has been quite a challenge, but I do believe that I have arrived at a workable solution which can easily be integrated into your existing Database Structure. Download the Attachment and look over it carefully. Should you have any questions, please post the relevant code, if any, along with as much detail as possible.
Attached Files
File Type: zip Scores.zip (27.6 KB, 85 views)
Dec 3 '10 #5

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

Similar topics

6
by: Piotr Pietrowski | last post by:
Hello everybody, I have a *big* problem. I thought its not that big problem for you professionals... Anyway, I have a begin date which has 3 dropdown boxes (day/Month/Year). The same for the...
6
by: Mark | last post by:
I'm looking for how to set up a query to return the record with the previous date to the most recent date. Example: ReturnDate: 11/15/03 12/12/03 2/4/04 4/5/04 The most recent date is...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
2
by: M.Stanley | last post by:
Hi, I have a problem..I'm doing a specific query where I'm joining fields from a table with appednded data (there are duplicate records, except for the date/time), and another query. I want the...
1
by: bmoos1 | last post by:
I need to make a Report of all people starting in 2004 by "Date Requested". Dates are entered as mm/dd/yyyy. I have a query that has all the people that started in 2004, but there are numerous...
1
by: Riley DeWiley | last post by:
I have an UPDATE query that is always setting 0 records. When I cut and paste the SQL into Access and use it, it fails in the same way unless I coerce the date fields to be '=now()', in which case...
7
by: CheezIt2831 | last post by:
hello, I have 5 tables(Alpha, Bravo, Charlie, Service, Trans). What i am trying to do is be able to select a start date and ending date for a report and include fields from the 5 tables. this is my...
2
by: favor08 | last post by:
7/19/2007 12:46:30 am. is in a field called CmplteDte. It is a date stamp of when the user completed the item. I need the time for a report but for a form that the supervisors use to QA the previous...
2
by: sudhaMurugesan | last post by:
Hi, I need to find the previous date from a given date in java script. Is there any code for it.Can anyone tell me.Thanks in advance
2
by: wevans | last post by:
I have 3 tables, Customer, Offsite Service and service. I need to create a sales report/query based on the results of the user input, which is a date range. I've got it working great with two of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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
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 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.