Jump to content

Sort And Group Data By Week.


sdbeach

Recommended Posts

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 by sdbeach
Link to comment
Share on other sites

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 by Christian F.
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.