This is my table
Create table gpscli
(
cliente int,/*this is my id client*/
inicio datetime,/*this is start time*/
fin datetime,/this is finished time**/
fecha datetime/*this is my date because inicio and fin could be a bad date*/
)
Table filled is something as this
select cliente, inicio, fin, fecha from gpscli order by fecha, cliente
1 '23-04-2012 10:23:51' '23-04-2012 10:26:38' '23-04-2012 00:00:000'
2 '23-04-2012 10:28:41' '23-04-2012 10:30:12' '23-04-2012 00:00:000'
3 '23-04-2012 10:33:58' '23-04-2012 10:37:24' '23-04-2012 00:00:000'
4 '23-04-2012 10:40:42' '23-04-2012 10:43:12' '23-04-2012 00:00:000'
5 '23-04-2012 10:45:46' '23-04-2012 10:57:18' '23-04-2012 00:00:000'
1 '24-04-2012 10:23:12' '24-04-2012 10:26:28' '24-04-2012 00:00:000'
2 '24-04-2012 10:23:29' '24-04-2012 10:26:58' '24-04-2012 00:00:000'
3 '24-04-2012 10:23:23' '24-04-2012 10:26:56' '24-04-2012 00:00:000'
4 '24-04-2012 10:23:12' '24-04-2012 10:26:28' '24-04-2012 00:00:000'
5 '24-04-2012 10:23:29' '24-04-2012 10:26:58' '24-04-2012 00:00:000'
1 '24-05-2012 10:23:12' '24-05-2012 10:26:28' '24-05-2012 00:00:000'
2 '24-05-2012 10:23:29' '24-05-2012 10:26:58' '24-05-2012 00:00:000'
3 '24-05-2012 10:23:23' '24-05-2012 10:26:56' '24-05-2012 00:00:000'
4 '24-05-2012 10:23:12' '24-05-2012 10:26:28' '24-05-2012 00:00:000'
5 '24-05-2012 10:23:29' '24-05-2012 10:26:58' '24-05-2012 00:00:000'
This information is saved by a user at this time would be called “supervisor”
supervisor is person which go store on store question what products client is going to want.
So he (supervisores) moves in car. When he opened a windows (in pockec pc), “inicio” is saved and when supervisor close the windows then “fin” is saved in database.
Now with this information I could get how time supervisor took with a client by mes, but I really need is, how long time supervisor took for move between client by mes.
Not client 1 is necessary the first client for one day, the first client is which has the min on inicio column. same for the last client with fin column.
How long time supervisor took for move between client by mes.
I need something as it
- for first client transfer time is 0.
- for second client, transfer time is
inicio(thisiniciocolumn is of current)- fin(thisfinis the former client) - for third client, transfer time is
inicio(this inicio column is of current)- fin(thisfinis the former client)
Finally I’ll need group by month,client
I don’t have idea how to get it (without using a loop, I wouldn’t like use it)
I could solved
now i have the finished time called as “fin_anterior” and now i can group by client, month or how it was necessary