Solved

SQL Query

Posted on 2014-11-03
8
88 Views
Last Modified: 2014-11-10
Hi, Expert
We have gps system each time device sending data every minute , if the vehicle is moving it has speed data if the vehicle is stopped then speed =0
I need to Calculate the total stopped time and location of the vehicle where is stopped and how long.

Please send me if you have any example

Columns as describe below

devicenum      
latitude
longitude
speed      
systime
0
Comment
Question by:Asrar Azmi
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 40418930
Your query will be something like:
select count(*), latitude, longitude from YOUR_TABLE group by latitude, longitude where speed=0

Open in new window

This will give you the locations of vehicle where is stopped and how long.
regarding the total stop time regardless of where may be as this:
select count(*) from YOUR_TABLE  where speed=0

Open in new window

Put in mind the result is number of minutes as you said the data sending is every minute.
0
 

Author Comment

by:Asrar Azmi
ID: 40418953
Dear Expert,

Thanks for your quick reply ,
How we can display systime column also with particular location like Stop Duration Like From To date time.

Waiting your reply.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40418991
How about this:

with T1 as (
select *, sum(case speed when 0 then 0 else 1 end) over(order by systime) as MyGroup
from YOUR_TABLE)
select devicenum, latitude, longitude, min(systime) as MinTime, max(systime) as MaxTime
from T1
group by devicenum, latitude, longitude, MyGroup

Open in new window

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 40419137
select count(*), latitude, longitude from YOUR_TABLE group by latitude, longitude, min(systime) From, max(systime) To where speed=0

Open in new window

0
 

Author Comment

by:Asrar Azmi
ID: 40423361
Dear Ahmed,
Above Query have error can you fix it and send me again.
0
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 40423576
Dear asrar  and sorry for the mistake:
select count(*), devicenum, latitude, longitude from YOUR_TABLE group by devicenum, latitude, longitude, min(systime) FromTime, max(systime) ToTime where speed=0

Open in new window

Wish this solve the problem.
0
 

Author Comment

by:Asrar Azmi
ID: 40425796
Thanks dear Ahmed
Can you share your personal e-mail and contact details with me ?
0
 
LVL 8

Accepted Solution

by:
Ahmed Merghani earned 500 total points
ID: 40428665
No problem. I sent you a connection request @ linkedin.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction People like FTP.  It's a solid, stable, robust protocol for quickly transferring files between two hosts using TCP/IP.  In most cases it's much faster than SMB or CIFS, and certainly much easier to set up between organizations.  This…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question