Solved

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

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

705 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