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.
Author |
Topic |
syed498
Starting Member
5 Posts |
Posted - 2014-06-28 : 01:30:04
|
Hi Team,I am new to SQL. I have a small query which if addressed will be a great help. I have Microsoft SQL Server 2012.I have a table as below:Column1 Column2 Time Status1 Name1 2014-05-21 07:34:21.490 Status12 Name1 2014-05-21 15:52:19.043 Status23 Name2 2014-05-21 15:54:08.457 Status14 Name2 2014-05-21 16:02:33.900 Status25 Name3 2014-05-21 04:06:29.027 Status16 Name3 2014-05-21 04:24:34.850 Status27 Name4 2014-05-21 04:34:35.050 Status18 Name4 2014-05-21 04:34:37.045 Status2Now I want a result which subtracts Time of Status2 from Time of Status1 and gives me a result as below:Column1 DifferenceName1 Difference of Status2 minus Status1 time in MinutesName2 Difference of Status2 minus Status1 time in MinutesName3 Difference of Status2 minus Status1 time in MinutesName4 Difference of Status2 minus Status1 time in MinutesLet me know if you need any more clarity.Thanks in Advance,Rushad |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-06-29 : 23:42:20
|
assuming that your records are in pairSELECT Column2, DATEDIFF(MINUTE, MIN(Time), MAX(Time))FROM yourtableGROUP BY Column2 KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|