?
Solved

MySQL Query - Max difference between date fields during one month period

Posted on 2008-06-25
4
Medium Priority
?
758 Views
Last Modified: 2008-07-07
We have an orders table that has a field called "sold_date" and another field called "rep_id"

Over a one month time period we want to see the AVERAGE number of days between sold_date and the MAXIMUM for each rep.

Any thoughts on how to do this?
0
Comment
Question by:944media
[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
4 Comments
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 21871185
Something like this?

SELECT
  rep_id,
  Avg((
    Select Max(sold_date)
    From TheTable B
    Where B.rep_id=A.rep_id
  )-sold_date) AS the_average
FROM TheTable A
GROUP BY rep_id;

(°v°)
0
 
LVL 58

Expert Comment

by:harfang
ID: 21929628
944media,

Please provide sufficient feedback so that I can understand why you did not follow up on this question.

Thank you
(°v°)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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