473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Grouping data by week?


Folks,

We have table that cointains timesheet entries for the employees.

Given user name, start date, and end date I want to get sum of hours for
each project, for each week.

Exmaple: Table looks like

UserName, Date, Project, Hours.

Suppose input is: shah, 2005-12-01, 2005-12-07.

2005-12-01 is on Thursday so I want to start from Sunday 2005-11-27,
2005-12-07 is on Wednesday so I want to end on Saturday 2005-12-10.

The output should look like:

Week of 2005-11-27

ProjectA 12
ProjectB 5
ProjectC 20
Week of 2005-12-04

ProjectA 21
ProjectB 15
ProjectC 0
Is there a DB2 function that will give me first day of week?
How can I group the sum of hours of the project by week?
Thanks.
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Jan 5 '06 #1
5 9078
Hemant Shah wrote:
Folks,

We have table that cointains timesheet entries for the employees.

Given user name, start date, and end date I want to get sum of hours for
each project, for each week.

Exmaple: Table looks like

UserName, Date, Project, Hours.

Suppose input is: shah, 2005-12-01, 2005-12-07.

2005-12-01 is on Thursday so I want to start from Sunday 2005-11-27,
2005-12-07 is on Wednesday so I want to end on Saturday 2005-12-10.

The output should look like:

Week of 2005-11-27

ProjectA 12
ProjectB 5
ProjectC 20
Week of 2005-12-04

ProjectA 21
ProjectB 15
ProjectC 0
Is there a DB2 function that will give me first day of week?
How can I group the sum of hours of the project by week?
Thanks.

GROUP BY YEAR(dt), WEEK(dt)
Or week_iso() depending whether your week starts Sunday or Monday...

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 5 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Serge Rielau wrote:
...
GROUP BY YEAR(dt), WEEK(dt)
Or week_iso() depending whether your week starts Sunday or Monday...

Cheers
Serge


On thing to mention. Looking at 01/01/2006 would give a wrong result, since the
year is 2006 but the week is 52 if the week starts on Monday.

Regards
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1rc2 (MingW32)

iD8DBQFDvX09yeCLzp/JKjARAgNRAJ9ZtPkXIYJFFdjnjsDjmp20gdjghACZAfce
YCbJ3zKrFPPFNDBnl2bsaQU=
=0SIN
-----END PGP SIGNATURE-----
Jan 5 '06 #3
Stefan Rybacki wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Serge Rielau wrote:
...
GROUP BY YEAR(dt), WEEK(dt)
Or week_iso() depending whether your week starts Sunday or Monday...

Cheers
Serge

On thing to mention. Looking at 01/01/2006 would give a wrong result, since the
year is 2006 but the week is 52 if the week starts on Monday.

Regards
Stefan

True... I suppose a simple CASE-expression wrapping the YEAR() group
could solve this. An exercise for the attentive reader :-)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 6 '06 #4
Ian
Hemant Shah wrote:
Folks,

We have table that cointains timesheet entries for the employees.

Given user name, start date, and end date I want to get sum of hours for
each project, for each week.

Exmaple: Table looks like

UserName, Date, Project, Hours.

Suppose input is: shah, 2005-12-01, 2005-12-07.

2005-12-01 is on Thursday so I want to start from Sunday 2005-11-27,
2005-12-07 is on Wednesday so I want to end on Saturday 2005-12-10.

You can use the expression:

date_column - dayofweek_iso(date_column) days

to calculate the week's starting date (assuming weeks start on Sunday).

Jan 6 '06 #5
While stranded on information super highway Ian wrote:
Hemant Shah wrote:
Folks,

We have table that cointains timesheet entries for the employees.

Given user name, start date, and end date I want to get sum of hours for
each project, for each week.

Exmaple: Table looks like

UserName, Date, Project, Hours.

Suppose input is: shah, 2005-12-01, 2005-12-07.

2005-12-01 is on Thursday so I want to start from Sunday 2005-11-27,
2005-12-07 is on Wednesday so I want to end on Saturday 2005-12-10.

You can use the expression:

date_column - dayofweek_iso(date_column) days

to calculate the week's starting date (assuming weeks start on Sunday).


Thanks I will give it a try.


--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Jan 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alicia | last post by:
Hi, I am trying to group by week and do a count of my data in between the dates. In Microsoft Access. Something similar to Before: Date Count --------- ---------...
5
by: Alicia | last post by:
Yes, but will that skip a week and group by the date for me? I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date ...
5
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to...
1
by: John | last post by:
I'm building a report where each row represents one month and its 1 to 5 weeks. A report query groups the source table date into a "month and year" expression. A subreport links to the main report...
1
by: jnikle | last post by:
I have a report that has three grouping levels: month, week, and days. In each of the footers for these groups I calculate a sum. If the number of records for a given week won't fit on one page,...
3
by: Bob | last post by:
I wish to group data on a report by week, month and year. Crystal reports has this ability as a built in function. Is there a quick way to do this in Access97/2000 VBA reports ? Thank you in...
7
by: derekdeben | last post by:
Hi, I have created a report that totals the number of days it took a product to ship by percentage by a date range for a specific location. My data comes from a query with the following headers: ...
3
by: Matt | last post by:
Hi All, I have the following situation: I admin a metrics database that includes an attendance piece that collects hours worked. From this data I show overtime as any amount of hours over 40...
12
kcdoell
by: kcdoell | last post by:
Hello: I just learned how to put crosstabs queries together but this one in particular is adding a new dimension in which I was hoping someone could give me some direction. I have the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.