bubbadawg Posted February 23, 2009 Share Posted February 23, 2009 I have a projects_tbl setup with the following fields: project_id, project, hours, and date. I am trying to run a query that will return each (unique) project, total hours for the entire project and number of days the project took to complete (difference between first date entry and last date entry). I am able to come up with part of the query: "SELECT project, SUM(hours) AS hours from projects_tbl GROUP BY project." However, I am thinking that the remaining part might be above my pay grade as I am not a MySQL expert. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/146568-help-with-complex-query/ Share on other sites More sharing options...
fenway Posted February 24, 2009 Share Posted February 24, 2009 You should be able to get MAX(yourDate) and MIN(yourDate) and then do the math. Quote Link to comment https://forums.phpfreaks.com/topic/146568-help-with-complex-query/#findComment-770172 Share on other sites More sharing options...
bubbadawg Posted February 26, 2009 Author Share Posted February 26, 2009 Can my entire query be done in one SQL statement? This is where I seem to be getting tripped up as I am not sure of the exact syntax to get my desired results. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/146568-help-with-complex-query/#findComment-771870 Share on other sites More sharing options...
bubbadawg Posted February 26, 2009 Author Share Posted February 26, 2009 Okay, I think this will return what I need unless there is a better / more efficient way to do it. SELECT project, MAX(date), MIN(date), SUM(hours) from projects_tbl GROUP BY project Quote Link to comment https://forums.phpfreaks.com/topic/146568-help-with-complex-query/#findComment-771875 Share on other sites More sharing options...
fenway Posted February 28, 2009 Share Posted February 28, 2009 Yup. Quote Link to comment https://forums.phpfreaks.com/topic/146568-help-with-complex-query/#findComment-773299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.