If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Help with SQL query.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-04, 10:01
innale innale is offline
Registered User
 
Join Date: Feb 2004
Posts: 1
Help with SQL query.

Hi, I have table Games(ClientID, WinDate, Score)
and I need to get the set of 3 best scores for each ClientID per a day,
where day is "05:00:00 - 04:59:59".

I'm using MS SQL Server and I can use sp and I can use more then one queries and cursors, but I have no idea how to make this script.
The main problem is to make grouping by day with such definition of the day.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 02-18-04, 14:06
joebednarz joebednarz is offline
Registered User
 
Join Date: Dec 2003
Location: Oklahoma, USA
Posts: 354
I'm an Oracle guy, so this is how you could do this in Oracle, but maybe it will help you if there is a graceful translation to MS SQL.

Code:
SELECT score, windate
FROM ( 
   SELECT score, windate
   FROM games 
      WHERE rowid<= 3 
      AND clientid = var
      AND WinDate BETWEEN 
         (TO_DATE( TO_CHAR( SYSDATE-1 ) || ' 17:00:00'), 'dd-MON-yyyy hh24:mi:ss' ) AND
         (TO_DATE( TO_CHAR( SYSDATE ) || ' 16:59:59'), 'dd-MON-yyyy hh24:mi:ss' )
   ORDER BY score
)
rowid is the order in which the results are returned, SYSDATE is the current system date.

Hope this helps or at least helps you think of another solution.

JoeB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On