473,789 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grouping with two Criterion and time point structure

9 New Member
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 1342
ck9663
2,878 Recognized Expert Specialist
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
sqlbraindead
9 New Member
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 Recognized Expert Specialist
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
sqlbraindead
9 New Member
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 Recognized Expert Specialist
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
sqlbraindead
9 New Member
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
2178
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 it from a traditional programming point of view. I have did quite a bit of searching but have found no answers to my particular problem... please read below XML for the problem I am having.
17
3134
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 absolute address of alpha to access to it. What confuses me is that when the variable is dynamically allocated, how does the compiler implement it? We know the address of the variable until run-time. During the compilation, how can we access to the...
2
1704
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 multiple nodes?" I will use an example to try to explain what I need to do and what I have for data. The example might not be very realistic but it's much easier than to try and explain using the scenario I have =P Suppose I had a list of...
8
3538
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 the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
1
2510
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. first, let me say that this is a really long post. i wasn't sure how much information/ background to provide, so i thought more was better than less. i tried to delineate certain areas so that it would be easy to peruse my posting and find...
1
1594
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 using the query's "month and year" expression. Problem is I can't figure out how to group the source table's dates into a "Mmmm yyyy" and then link the subreport to the relevant week of that "Mmmm Yyyy". source table:
10
4790
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 structures are read only) Ideally one should be able to put the redundant information there automatically so no mistakes are possible, but in a lot of case I see no way how to do it.
4
1573
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 something1,item2,somethingelse3 something1,item2,somethingelse4 something2,item1,somethingelse5
0
1536
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 more information. 'de_AT.utf8' {'mon_decimal_point': ',', 'int_frac_digits': 2, 'p_sep_by_space': 1, 'frac_digits': 2, 'thousands_sep': '', 'n_sign_posn': 1,
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.