473,406 Members | 2,343 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,406 software developers and data experts.

Grouping with two Criterion and time point structure

The problem is if I want to group my database on the time basis, how can reconcile the grouping of two different criteria structure?

This is an example.
Two table I want to use these to get a table with each staff and calculate their total working hours.

Master Table (2 Columns)
StaffID Grade
1 A
2 A
3 B
4 C
5 D
6 E

Work Hour Table (5 Columns)
StaffID Grade HourType Date WorkingHours
1 A Holiday 11/01/2008 8
2 A Holiday 11/01/2008 8
2 A Holiday 13/01/2008 4
4 C Holiday 11/01/2008 8
4 C Regular 12/01/2008 7
4 C Regular 13/01/2008 4
6 E Holiday 11/01/2008 8
6 E Regular 12/01/2008 5
6 E Regular 13/01/2008 6
5 D Regular 11/01/2008 6
5 D Regular 12/01/2008 7
5 D Regular 13/01/2008 5


The logic is:
If Grade B or above, they will not record regular work hours, only holiday will be recorded. On regular working day, Grade B or above will be given 7 hours working hours. The others are recorded by their working hours.


Result Table: 3 Days 11/01/2008 – 13/01/2008 Working Hours (3 Columns)
StaffID Grade Workinghours
1 A 22
2 A 19
3 B 21
4 C 19
5 D 18
6 E 19

My issue here is I am successfully group 1 date data to cal the salary for each day. But when it comes to more than 1 day, let say 3 days, I have got problem. For the Grade B or above, there can be a logic like count the holidays for grade B or above, then the total days minus the holidays. The resulting days will be multiplied by 7. The others just get the sum of their working hours with criteria of the start and end days.
But I can’t put this in SQL.
Jan 17 '08 #1
6 1326
ck9663
2,878 Expert 2GB
The problem is if I want to group my database on the time basis, how can reconcile the grouping of two different criteria structure?

This is an example.
Two table I want to use these to get a table with each staff and calculate their total working hours.

Master Table (2 Columns)
StaffID Grade
1 A
2 A
3 B
4 C
5 D
6 E

Work Hour Table (5 Columns)
StaffID Grade HourType Date WorkingHours
1 A Holiday 11/01/2008 8
2 A Holiday 11/01/2008 8
2 A Holiday 13/01/2008 4
4 C Holiday 11/01/2008 8
4 C Regular 12/01/2008 7
4 C Regular 13/01/2008 4
6 E Holiday 11/01/2008 8
6 E Regular 12/01/2008 5
6 E Regular 13/01/2008 6
5 D Regular 11/01/2008 6
5 D Regular 12/01/2008 7
5 D Regular 13/01/2008 5


The logic is:
If Grade B or above, they will not record regular work hours, only holiday will be recorded. On regular working day, Grade B or above will be given 7 hours working hours. The others are recorded by their working hours.


Result Table: 3 Days 11/01/2008 – 13/01/2008 Working Hours (3 Columns)
StaffID Grade Workinghours
1 A 22
2 A 19
3 B 21
4 C 19
5 D 18
6 E 19

My issue here is I am successfully group 1 date data to cal the salary for each day. But when it comes to more than 1 day, let say 3 days, I have got problem. For the Grade B or above, there can be a logic like count the holidays for grade B or above, then the total days minus the holidays. The resulting days will be multiplied by 7. The others just get the sum of their working hours with criteria of the start and end days.
But I can’t put this in SQL.

where did you get this:

2 A 19
3 B 21

-- CK
Jan 17 '08 #2
where did you get this:

2 A 19
3 B 21

-- CK
2 is the id and A is the given grade hence 19 = 8 + 4 + 7. 8 is the holiday hour on 11/01/2008. 4 is the holiday hour on 13/01/2008 and the remaining day 12/01/2008. It doesn't get recorded because he is grade A, so 7 hours are given.

for id3, 21 = 7 * 3 since it is not recorded at all in the Work Hour Table and he is grade B, so 7 hours is given for each day. For 3 days, it is 21.
Jan 17 '08 #3
ck9663
2,878 Expert 2GB
2 is the id and A is the given grade hence 19 = 8 + 4 + 7. 8 is the holiday hour on 11/01/2008. 4 is the holiday hour on 13/01/2008 and the remaining day 12/01/2008. It doesn't get recorded because he is grade A, so 7 hours are given.

for id3, 21 = 7 * 3 since it is not recorded at all in the Work Hour Table and he is grade B, so 7 hours is given for each day. For 3 days, it is 21.

got it... i think you might need more than just a simple query here...the reason is the work/shift table is not complete. you have to check if something is missing and assume (7 hours) if they are not recorded...

i think cursor is your best path...

-- CK
Jan 17 '08 #4
got it... i think you might need more than just a simple query here...the reason is the work/shift table is not complete. you have to check if something is missing and assume (7 hours) if they are not recorded...

i think cursor is your best path...

-- CK
Any idea of how to put the codings?

(CASE WHEN PRSRG < 'B' THEN (CASE WHEN APINC = 'HOLIDAY' THEN APHRS ELSE 7 END)
ELSE APHRS END) END) AS Workhrs

This is part of the logic that I use in view to get the daily working hours. However, can I use a looping to get round the problem of the incomplete database for multiple day grouping. Or another attempt that I failed is to create a new tempoary table to make the grouping easier to handle. Any idea is appreciated!!

Thanks.
Jan 18 '08 #5
ck9663
2,878 Expert 2GB
on your first posting. when you said, not recorded, do you mean it's not on the table (no record on the table?) or you just did not include it on the sample data?

-- CK
Jan 18 '08 #6
on your first posting. when you said, not recorded, do you mean it's not on the table (no record on the table?) or you just did not include it on the sample data?

-- CK
They won't be on the Work Hour Table because they will automatically recorded as 7 hrs if it is not holiday.
Jan 18 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jody Greening | last post by:
Transforming with XSLT, Grouping elements until difference found. I am seeking some help with the following problem, I am fairly new at XSLT transformations, and my problem may lie in looking at...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
2
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
1
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals....
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...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
4
by: mantrid | last post by:
I have records from a database that are extracted with php and displayed in a table. Data in some of the fields is replicated eg something1,item1,somethingelse1 something1,item1,somethingelse2...
0
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.