Jump to content

Specific Query Based on Date Difference


bdmovies

Recommended Posts

I need 3 queries. I can figure out the 1st one, but need help with the other 2.

 

I've got a column that stores the dateReceived of a job. I need to get total number of jobs where the dateReceived is greater than 10 days ago.  I also need the same thing for jobs received more than 7 days ago but less than 10. And last but not least I need all the jobs received 7 days or less. I think I've got 1 query done so far.

 

SELECT COUNT(DATEDIFF(serviceJob.dateReceived, DATE_SUB(CURRENT_DATE(), INTERVAL 10 DAY))) AS over10 FROM serviceJob WHERE serviceStatus = '0'

 

To be honest, I'm sure there is a much better way to do this, but I'm having quite a bit of trouble. Also, I have no idea how to go about the greater than 7 under 10 query.

Link to comment
Share on other sites

Does this help?  You might as well use multiple queries... or subqueries if you prefer.

 

I need to get total number of jobs where the dateReceived is greater than 10 days ago.

SELECT COUNT(*) FROM .... WHERE serviceJob.dateReceived < CURDATE() - INTERVAL 10 DAY

 

I also need the same thing for jobs received more than 7 days ago but less than 10.

SELECT COUNT(*) FROM .... WHERE serviceJob.dateReceived BETWEEN CURDATE() - INTERVAL 10 DAY AND CURDATE() - INTERVAL 7 DAY

 

And last but not least I need all the jobs received 7 days or less.

SELECT COUNT(*) FROM .... WHERE serviceJob.dateReceived >= CURDATE() - INTERVAL 7 DAY

 

Link to comment
Share on other sites

  • 1 month later...

Does this help?  You might as well use multiple queries... or subqueries if you prefer.

 

I need to get total number of jobs where the dateReceived is greater than 10 days ago.

SELECT COUNT(*) FROM .... WHERE serviceJob.dateReceived < CURDATE() - INTERVAL 10 DAY

 

I also need the same thing for jobs received more than 7 days ago but less than 10.

SELECT COUNT(*) FROM .... WHERE serviceJob.dateReceived BETWEEN CURDATE() - INTERVAL 10 DAY AND CURDATE() - INTERVAL 7 DAY

 

And last but not least I need all the jobs received 7 days or less.

SELECT COUNT(*) FROM .... WHERE serviceJob.dateReceived >= CURDATE() - INTERVAL 7 DAY

 

I want to ask you, what if i want to get date greater then 60 days which means one year earlier.

Sorry for bad english, let me i try to explain.

I want to get person who registered in LAST 60 days, but we are January now so i need get the data from 2008/11/21 to 2009/01/21. with your query i can get only 4 members instead of 12 members.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.