Solved

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

Posted on 2008-06-25
4
703 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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
'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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now