Solved

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

Posted on 2008-06-25
4
734 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
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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