Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Query with count of duplicates

Posted on 2011-02-19
3
Medium Priority
?
276 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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