🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #779

Re: SQL Help

#779
From: Jeff Overcash (TeamB)
Date: Thu, 12 Jul 2007 22:43
53 lines
2363 bytes
Roy wrote:
> Hi,
> 
> I have an Interbase table with the following fields
> 
> START_DATETIME
> TRAFFIC
> ROUTE_NAME
> 
> I want to be able to retrieve the MAX(TRAFFIC) for a particular ROUTE_NAME 
> on a particular day (0ne record for the day) ;
> 
> but the Select statement
> 
> 
> SELECT START_DATE,ROUTE_NAME, MAX(TRAFFIC) from SYSTRAFFIC where 
> START_DATETIME  = '2007/1/1'  GROUP BY
> START_DATETIME,ROUTE_NAME
> 
> 
> returns all values for the traffic for all the hours of the day (24 Records)
> 
> How can I achieve that.
> 
> 
> Thanks very much for your help.
> 
> Rgds
> Roy 
> 
> 

You will get the max of the combination of START_DATE,ROUTE_NAME with this SQL. 
  To get the route and max traffic for that route use

SELECT ROUTE_NAME, MAX(TRAFFIC)
   from SYSTRAFFIC
  where START_DATETIME  = '2007/1/1'
  GROUP BY ROUTE_NAME

Then go back and get the start_date based on route_name, traffic and 
start_datetime.  This could probably be turned into a selectable stored 
procedure to get all three in a single DB call.


-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
Technical Details
Message-ID: <4696ae81$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46969c24@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,8f88f6177bf0b125
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 12 Jul 2007 18:43:13 -0400
From: "Jeff Overcash (TeamB)" <jeffovercash@mindspring.com>
Organization: TeamB
User-Agent: Thunderbird 2.0.0.4 (Windows/20070604)
MIME-Version: 1.0
Newsgroups: borland.public.interbase.sql
Subject: Re: SQL Help
References: <46969c24@newsgroups.borland.com>
In-Reply-To: <46969c24@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 66.32.128.180
Message-ID: <4696ae81$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1184280193 66.32.128.180 (12 Jul 2007 15:43:13 -0700)
Lines: 53
X-Authenticated-User: overcash
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail