Solved

SQL Query

Posted on 2014-11-03
8
87 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Title # Comments Views Activity
Writing SQL Select Query result to a text file 12 46
How can i get data when i use where clause with group by? 3 35
SQL Server stored proc 2 19
Webservices in T-SQL 3 30
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 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