MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 8th, 2004, 01:54 PM
mydan mydan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 mydan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SQL for a scoreboard

Hi,

My loathe for MS SQL is growing by the minute, maybe someone can help.

OK it's a scoreboard scenario. (Using ASP / Access DB)

There are 6 fields we're interested in found in a table called Records

ID - autonum
Alias - string
DateTime - date/time
LapTime - long integer
TrackID - integer
CraftID - integer


I want the sql to:

1. return the results from the table where TrackID = 1 and CraftID = 0.
2. order the results by LapTime ascending.
3. return only the best result per unique Alias. (there's several laptimes per alias, and many aliases, obviously). The best can be defined as the lowest LapTime.

Apply those rules to the same query (e.g. I don't want separates)

I've come up with so many statements, they either fall over in some way or I get a niggly error. Some help here would really be appreciated.

Sounds 'easy' doesn't it?
It probably is, but not for me anyway. This 'language' is probably the worst one in existance, and it shouldn't be.

Dan

Reply With Quote
  #2  
Old April 8th, 2004, 02:49 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,581 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 5 h 20 m 45 sec
Reputation Power: 949
this is easy, if you know about correlated subqueries, which, i guess, is not always the first thing you learn, and definitiely pretty hard to figure out on your own
Code:
select ID
     , Alias
     , DateTime
     , LapTime
     , TrackID
     , CraftID
  from Records zzzzzz
 where TrackID = 1 
   and CraftID = 0  
   and LapTime
     = ( select min(LapTime)
           from Records
          where Alias = zzzzzz.Alias )    
order 
    by LapTime asc
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old April 8th, 2004, 06:10 PM
mydan mydan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 mydan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi there mate,

I have to thank you really for your help, your query was missing the TrackSum and CraftID conditions from the WHERE clause, other than that it worked PERFECTLY.


THANKS once again my friend

Dan


you can check it out at URL

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL for a scoreboard


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway