Jump to content

Recommended Posts

Hi all,

 

Can someone point me in the right direction with the below MYSQL statement? I'm trying to create buckets of "timeframes" that a specific item is received and when it is released (cycle time).  I want to be able to count the amount of items that fall within each time frame.  The below statement works but its not the best way to do since i do want to add a time period to it later such as sample set for each month.

 

"Select

(select count(*) from Table where DATEDIFF(Release, Arrival ) < 0) as less0,

(select count(*) from Table where DATEDIFF(Release, Arrival ) = 0) as 0day,

(select count(*) from Table where DATEDIFF(Release, Arrival ) BETWEEN 1 and 5) as 1to5,

(select count(*) from Table where DATEDIFF(Release, Arrival ) BETWEEN 6 and 10) as 6to10"

 

 

Link to comment
https://forums.phpfreaks.com/topic/183069-cycle-time-datediff/
Share on other sites

You could try something along the lines of this.  Which would enable you to come back and add in a where clause.  Also this only requires reading in the table once.

 

Select sum(if(DATEDIFF(Release, Arrival ) < 0, 1, 0)) as less0, sum(if(DATEDIFF(Release, Arrival ) = 0, 1, 0)) as 0day, sum(if(DATEDIFF(Release, Arrival ) BETWEEN 1 and 5, 1, 0)) as 1to5, sum(if(DATEDIFF(Release, Arrival ) BETWEEN 6 and 10, 1, 0)) as 6to10
FROM table

Link to comment
https://forums.phpfreaks.com/topic/183069-cycle-time-datediff/#findComment-966430
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.