Solved

SQL Query with count of duplicates

Posted on 2011-02-19
3
262 Views
Last Modified: 2012-05-11
I have trucks entereing different loading zones. Each time the truck enters a loading zone, it makes an entry into our mysql table witht the following fields:  id, truckName, date, latitude, longitude, speedInZone, zoneName. Through out the day the trucks will enter a leave the zone multiple times.  I need to pull the following data:

truckName, DateTime of last entry in this zone, zoneName, Count of how many times this truck entered this zone.

I am thinking maybe a group by truckName, zoneName may be the right direction but I need a little help.
0
Comment
Question by:dtechfish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 34934896
try this

SELECT truckName, MAX(date) AS lastentry, zoneName, COUNT(*)
 FROM yourTable
 GROUP BY truckName, zoneName
 
0
 
LVL 41

Expert Comment

by:Sharath
ID: 34934904
try this.
select id,zonename,count(*) cnt,max(date) last_entry
  from your_table
 group by id,zonename

Open in new window

if you did not get what you are looking for, provide some sample data with expected result.
0
 
LVL 41

Expert Comment

by:Sharath
ID: 34934908
replace id with truckname in my query. tigin got it
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

622 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