Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

sql statement,

SQL
  SELECT CONVERT(VARCHAR(10), VRS_UTCTIME, 121) AS [Date],
MIN(SUBSTRING(CONVERT(VARCHAR(23), VRS_UTCTIME, 121), 12,20)) AS [start_time],
MAX(SUBSTRING(CONVERT(VARCHAR(23), VRS_UTCTIME, 121), 12,20)) AS [stop_time],
MAX(VRS_SPEED) AS [max_speed]
FROM STS_VEHICLE_RUNNING_STATUS
WHERE VRS_DEVICEID = 'ST0001' AND  VRS_UTCTIME BETWEEN '2012-07-02' AND '2012-11-09'
GROUP BY CONVERT(VARCHAR(10), VRS_UTCTIME, 121)


retrieve data from table as,


 Date            start_time         stop_time    max_speed
----              ----------     ---------       ---------
2012-07-02        10:59:26.000    11:33:36.000      40

2012-09-06        18:45:29.000   19:46:28.000      0.36

2012-10-09        12:10:12.000    01:12:12.000      50


but i want to retrieve the location point at this max_speed value.how can write
sql statement to retrieve the location point data with this result?

ie,
sql,
SQL
SELECT VRS_LATITUDE FROM STS_VEHICLE_RUNNING_STATUS
WHERE VRS_SPEED=(SELECT MAX(VRS_SPEED) FROM STS_VEHICLE_RUNNING_STATUS)


'How SQL retrieving max value plus corresponding another column value'?
-----------------------------------------------------------------------

plz help me...

Thanks


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 16-Nov-12 21:50pm
v4

1 solution

Just add
SQL
SELECT TOP 1 * FROM (
{YOUR SQL}
) temp
order by max_speed desc


Whis way you will retrieve 1 row with maximum max_speed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900