sdbeach Posted September 24, 2012 Share Posted September 24, 2012 (edited) I would like to query a database named 'data' and have it pull all information for a specific job by week and have it grouped by 'name'. My table is shown below. id admin_hrs shop_hrs fab_hrs paint_hrs vacation_hrs control_hrs test_hrs engine_hrs hydraulic_hrs date active bid_hrs name lead job I have used the below query to get the information that I want for all dates, but cannot figure out how to separate them by weeks. Below is the result for my query for all entries using the statement below.... $query = "SELECT job, date, name, SUM(test_hrs),SUM(fab_hrs),SUM(control_hrs),SUM(shop_hrs),SUM(paint_hrs),SUM(engine_hrs),SUM(hydraulic_hrs) FROM data WHERE job LIKE '%" . $job . "%'GROUP BY name"; NAME LABOR TOTALS CAIN CHARLES 1 CHANDLER JAMES 4 FRONCK WILLIAM 13 GEORGE SETH 5 GRAHAM JOHN 4.75 HIGGINS ERIC 4.5 THEIL ALEC 0.5 WILSON ALLEN 9.5 I would like it to have a column of "week number" like below... Week NAME LABOR TOTALS 1 CAIN CHARLES 1 1 CHANDLER JAMES 3 2 CHANDLER JAMES 4 1 FRONCK WILLIAM 4 2 FRONCK WILLIAM 23 3 FRONCK WILLIAM 13 They would not pick a date, it would just see the date field and sort by the week. I have read documentation on the week() function but cannot get the desired results. I put the query in a while loop to get the records displayed. Any help would be greatly appreciated! Edited September 24, 2012 by sdbeach Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 (edited) Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read. Also, posting an example of what you got from the failed query, plus what you expected from it, would go a long way in helping us helping you. Edited September 24, 2012 by Christian F. Quote Link to comment Share on other sites More sharing options...
sdbeach Posted September 25, 2012 Author Share Posted September 25, 2012 Thanks for the guidance. I am going to rewrite this properly and re-post. Thanks for this site! Quote Link to comment 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.