Solved

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

Posted on 2008-06-25
4
741 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 500 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…

749 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