Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a table in which the following values exist.

CSS
Client_Id   Load_1  RTC
TS1733         1   8/21/2014 16:10
TS1733         1   8/21/2014 17:00
TS1733         1   8/21/2014 17:10
TS1733         1   8/21/2014 17:20
TS1733         1   8/21/2014 17:30
TS1733         0   8/21/2014 17:40
TS1733         0   8/21/2014 17:50
TS1733         1   8/21/2014 18:00
TS1733         1   8/21/2014 18:10
TS1733         1   8/21/2014 18:20
TS1733         1   8/21/2014 18:40



I want to fetch total duration of time of Client_ID when it was 1 and 0.

Result

CSS
Client_ID	Load_1	TimeDuration(Minute)
TS1733	          1	    130
TS1733	          0	     20



How can i get the above result. Please help..
Posted
Comments
Mike Meinz 29-Aug-14 10:21am    

1 solution

Try:
SQL
SELECT Client_Id, Load_1, DATEDIFF(minute, MIN(RTC), MAX(RTC)) AS [TimeDuration(Minute)]
FROM MyTable
GROUP BY Client_id, Load_1
 
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