Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Sql query to display Max values for each ID's

$
0
0

Hi Team,

I have table that contains below data

Date                              ID             Message
2015-05-29 7:00:00      AOOze            abc
2015-05-29 7:05:00      AOOze            start
2015-05-29 7:10:00      AOOze            pqy
2015-05-29 7:15:00      AOOze            stop
2015-05-29 7:20:00      AOOze            lmn     
2015-05-29 7:25:00      LaOze            12a
2015-05-29 7:30:00      LaOze            start 
2015-05-29 7:35:00      LaOze            s34
2015-05-29 7:45:00      LaOze            stop
2015-05-29 7:45:00      LaOze            asr     
and so on following the series for every set of different ID with 5 entries

I need to Find Maximum interval time for each ID and for condition in given message (between Start and Stop)

For example, in above table
For ID AOOze, in message "start" is logged at 7:05 and stop and 7:15, so interval is 10 mins
For ID LaOze, in message "start" is logged at 7:30 and stop and 7:45, so interval is 15 mins

I am looking for a sql query that will return in below format

ID     MAX interval
AOOze   15
LaOze   10

Can you please help


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>