Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Need Max date?

Author  Topic 

gotafly
Yak Posting Veteran

54 Posts

Posted - 2005-02-28 : 12:10:29
Here is what I have so far:
SELECT DISTINCT SPEEDLOCATIONS.HWY, SPEED.SPEEDMPH, SPEED.DATETIME, SPEEDLOCATIONS.[CROSS]
FROM SPEEDLOCATIONS INNER JOIN
SPEED ON SPEEDLOCATIONS.ID = SPEED.ID
WHERE (SPEEDLOCATIONS.CITY = 'HOU')
ORDER BY SPEEDLOCATIONS.HWY, SPEEDLOCATIONS.[CROSS], SPEED.DATETIME DESC

--
Beltway 8-Nort 70 3/9/2004 1:45:45 PM Ella
Beltway 8-Nort 70 3/9/2004 1:36:12 PM Ella
Beltway 8-Nort 50 3/9/2004 12:47:12 PM Ella
Beltway 8-Nort 52 3/9/2004 12:47:12 PM Ella
Beltway 8-Nort 60 3/9/2004 11:45:56 AM Ella
Beltway 8-Nort 70 3/9/2004 1:42:20 PM Fairbanks at US-290
Beltway 8-Nort 70 3/9/2004 1:36:12 PM Fairbanks at US-290
Beltway 8-Nort 39 3/9/2004 12:47:12 PM Fairbanks at US-290
Beltway 8-Nort 58 3/9/2004 12:47:12 PM Fairbanks at US-290
Beltway 8-Nort 45 3/9/2004 11:45:56 AM Fairbanks at US-290
Hardy Tollroad 70 3/9/2004 1:42:14 PM Aldine-Bender
Hardy Tollroad 70 3/9/2004 1:42:08 PM Aldine-Bender
Hardy Tollroad 61 3/9/2004 12:47:12 PM Aldine-Bender
Hardy Tollroad 66 3/9/2004 12:47:12 PM Aldine-Bender
Hardy Tollroad 70 3/9/2004 12:46:17 PM Aldine-Bender


I just want to select the latest date for each SPEEDLOCATIONS/.[CROSS]

Beltway 8-Nort 70 3/9/2004 1:45:45 PM Ella
Beltway 8-Nort 70 3/9/2004 1:42:20 PM Fairbanks at US-290
Hardy Tollroad 70 3/9/2004 1:42:14 PM Aldine-Bender





David

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-02-28 : 16:17:06
How about: ???
select
speedlocations.hwy,
speed.speedmph,
speed.datetime,
speedlocations.[cross]
from
speedlocations
inner join speed
on speedlocations.id = speed.id
inner join( select
speedlocations.hwy,
max(speed.datetime) as maxdate,
speedlocations.[cross]
from
speedlocations
inner join speed
on speedlocations.id = speed.id
where
(speedlocations.city = 'hou')
group by
speedlocations.hwy,
speedlocations.[cross] ) as maxdate_per_hwy_cross
on speedlocations.hwy = maxdate_per_hwy_cross.hwy
and speedlocations.[cross] = maxdate_per_hwy_cross.[cross]
and speed.datetime = maxdate_per_hwy_cross.maxdate


rockmoose
Go to Top of Page
   

- Advertisement -