473,487 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sorting a complex query in ascending order

547 Contributor
This query is for a race taking place over 3 days.

The query adds up 100% and i can get the total times of athletes.

My only problem i have, is to sort the race times depending on whether a competitor finish the race or not.

If all the athletes are suppose to complete 3 days, and one athlete only manage to finish 2 of the 3, then that person's finish position in the race, should be last .

In the attached screen pic, it can be seen that RaceNo 3 (Ian Adams) did not complete day3time (third day of the race.)His time is therefore actually the worst of the 3 athletes, but now the shortest as he only did 2 days.

Looking at the Totaltime for the 3 athletes, RaceNo=2 (Shawn) has the best totaltime = 01:30(shortest for the 3 days), followed by RaceNo1 =(Michael) in 01.31 and last is RaceNo3 because he failed to do Day3time.

My question: how can i sort RaceNo 2 and 3 in ascending order, and if you have a "blank time" for an athlete, then that name appear last in the query?
I also include the actual query problem
pls help
Attached Images
File Type: jpg totaltimeprobl.jpg (33.5 KB, 129 views)
Attached Files
File Type: zip timesproblem2003_2.zip (50.7 KB, 67 views)
Jan 2 '11 #1
8 1384
ADezii
8,834 Recognized Expert Expert
Let me know if this is what you are looking for, and if it is, I'll explain the Logic, if need be of course.
Attached Files
File Type: zip timesproblem2003_3.zip (50.4 KB, 61 views)
Jan 3 '11 #2
neelsfer
547 Contributor
I have changed the tables but its still the same problem.
What i did not mention is that there can be up to 8 different times per RaceNo
If any Raceno (athlete) did not finish one or more of the "laps" , then that athlete's time should be at the bottom when the query is done.
I attached a new screen pic and adjusted database for 8 laps

My problem:
Only RaceNo 1 and 2 finished all the laps ie 8 in this case.
RaceNo 3 and 4 did not finish all 8.
I must sort on RaceNo 1 and 2 to get the overall positions in the race and RaceNo3 and 4 must appear after RaceNo 1& 2 in no specific order.
In the above example, RaceNo = 2 time 00:1:14 ( is the winner and should be on top followed by RaceNo =1 (00:1:18) etc
i wish this was a straight forward sort but these blank times create complications
Attached Files
File Type: zip timesproblem2003_3.zip (51.3 KB, 54 views)
File Type: zip laptimes probl.zip (20.5 KB, 60 views)
Jan 3 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Couldn't you group by a flag that determined whether or not they competed in all three races?
Jan 3 '11 #4
neelsfer
547 Contributor
in this instance the athlete has to complete 8 laps, but because of injury etc they may end up doing perhaps 6 only.
I have to sort those that do finish by their total time.
Jan 3 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
I know, that's why you should group by a flag. Either one that you create in the table or one that is calculated on the fly.
Jan 3 '11 #6
OldBirdman
675 Contributor
Why not add some amount of time, say 1 hour or 1 day, instead of 0 for any lap not completed. When you sort from lowest (fastest) time to highest(slowest), the times with 1 day added will be at the bottom of the list.
This will also rank those who only participated on some days. For your 3 day event, if an athelete competed 2 days, their time would be faster than someone who only competed 1 day, even if their 1 day time were slower than the average of the 2 day times.
Jan 3 '11 #7
ADezii
8,834 Recognized Expert Expert
I need to see a fully functional RT_XCAllLapsQ2 Query even if there are errors and the Records are not in the correct sequence. You latest Attachment does not show this.
Jan 4 '11 #8
neelsfer
547 Contributor
Got it right!! Thx to Mr "amazing" Adezzi.

I adapted his last post a bit and its working!

Sort the "blank" fields with this code (ascending), where 1 is when you have a time and 10 if its blank. The athletes that finished all the required laps are at the top and vice versa
Expand|Select|Wrap|Line Numbers
  1. Sort: IIf(Not IsNull([lap1]),IIf(Not IsNull([lap2]),IIf(Not IsNull([lap3]),"1","10")))
sort the "times" with this code in secondary ascending sorting
Expand|Select|Wrap|Line Numbers
  1. TotTime: Format$(IIf(IsNull([Lap1]-[Actualstarttime]),0,CDate([Lap1]-[ActualStartTime]))+IIf(IsNull([Lap2]-[Lap1]),0,CDate([Lap2]-[Lap1]))+IIf(IsNull([Lap3]-[Lap2]),0,CDate([Lap3]-[Lap2])),"hh:nn:ss")
The winner will be at the top

i will now adapt it further for 8 different lap times in total
Jan 4 '11 #9

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

Similar topics

1
8011
by: Karen Bailey | last post by:
Hi, I am attempting to write a complex query to group sets of data. I have my query working correctly, but i ran into a problem with sorting. I want to sort my query by a string field. Is...
6
5335
by: sriram | last post by:
Hi, I have been seing a weird problem with db2look tool in db2 8.2 on Windows 2000 platform. When i spool the DDL using db2look, it spools the DDL in the ascending order of database objects...
2
4123
by: fred_stevens | last post by:
Hi all you C boffins: I need to sort a vector of doubles is ascending order. Qsort will return the sorted vector, but I need a vector of the indices of the sorted vector, not the actual sorted...
2
4184
by: PRadyut | last post by:
In this code i tried to add the elements in ascending order but the output is only 0 1 2 the rest of the elements are not shown. the code...
2
3085
by: Joe | last post by:
Hi, I have an asp.net script that connects to MS Access database and displays data in a table. For some reason I am do not know how to display data say in ascending order of column1. I have...
5
9972
by: Nick Weisser | last post by:
Hi there, I'm not sure how to select the last 3 items in ascending order. This does the trick in descending order: select * from user_menu_main where deleted = 0 and hidden = 0 order by...
3
2160
by: Eric Lilja | last post by:
Hello, consider the following assignment and my code for it: /* Write a program that does the following: * Integer numbers shall be read from a textfile and stored in a std::vector. The name...
4
3634
by: neelesh kumar | last post by:
sir, i have a table named tblexam. i want to sort the whole table records according to the field subcode in ascending order. docmd.runsql "update tblexam order by subcode asc" But it is...
6
2821
by: flyaway888 | last post by:
Hey, I have a function that compares 2 arrays with 6 numbers in each and outputs the matching numbers. I have written a function that does this but I need to output the numbers in ascending order...
11
4656
by: ankitmathur | last post by:
Hi, I'm trying to overcome a situation whereby I have to search through 4-5 columns and produce the results with an order by according to the values matched in these columns. Example: My...
0
6967
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
7142
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,...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
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
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
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 ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.