Hi
I have 4 weeks data of employees.Based on matchingOff column i need to find no of employee who are getting weekOff on sameday for all 4weeks.Suppose emp 101 is getting weekOff on 8/1/2010(Sunday) if the employee gets weekOf on sameDay(i.e sunday) for all 4 weeks then count will be 1.Simiraly how many employees are getting weekoff like that and increment count.
WeekOff can be any day.If the employee gets weekoff on Monday for all 4 weeks then also count will be 1.Simiraly how many employees.
Please tell me how to query for this.
Insert into Testing1(empno,MatchingOff,atnDate)
select '101','Off','8/1/2010' union all
select '101','17:00','8/2/2010' union all
select '101','17:00','8/3/2010' union all
select '101','17:00','8/4/2010' union all
select '101','17:00','8/5/2010' union all
select '101','17:00','8/6/2010' union all
select '101','17:00','8/7/2010' union all
select '102','17:00','8/1/2010' union all
select '102','off','8/2/2010' union all
select '102','17:00','8/3/2010' union all
select '102','17:00','8/4/2010' union all
select '102','17:00','8/5/2010' union all
select '102','17:00','8/6/2010' union all
select '102','17:00','8/7/2010' union all
select '103','17:00','8/1/2010' union all
select '103','15:00','8/2/2010' union all
select '103','15:00','8/3/2010' union all
select '103','Off','8/4/2010' union all
select '103','17:00','8/5/2010' union all
select '103','17:00','8/6/2010' union all
select '103','17:00','8/7/2010' union all
select '104','17:00','8/1/2010' union all
select '104','15:00','8/2/2010' union all
select '104','15:00','8/3/2010' union all
select '104','15:00','8/4/2010' union all
select '104','Off','8/5/2010' union all
select '104','17:00','8/6/2010' union all
select '104','17:00','8/7/2010' union all
select '101','Off','8/8/2010' union all
select '101','16:00','8/9/2010' union all
select '101','16:00','8/10/2010' union all
select '101','Off','8/11/2010' union all
select '101','16:00','8/12/2010' union all
select '101','18:00','8/13/2010' union all
select '101','16:00','8/14/2010' union all
select '102','Off','8/8/2010' union all
select '102','Off','8/9/2010' union all
select '102','16:00','8/10/2010' union all
select '102','Off','8/11/2010' union all
select '102','16:00','8/12/2010' union all
select '102','18:00','8/13/2010' union all
select '102','16:00','8/14/2010' union all
select '103','Off','8/8/2010' union all
select '103','16:00','8/9/2010' union all
select '103','16:00','8/10/2010' union all
select '103','Off','8/11/2010' union all
select '103','16:00','8/12/2010' union all
select '103','18:00','8/13/2010' union all
select '103','16:00','8/14/2010' union all
select '104','Off','8/8/2010' union all
select '104','16:00','8/9/2010' union all
select '104','16:00','8/10/2010' union all
select '104','17:00','8/11/2010' union all
select '104','Off','8/12/2010' union all
select '104','18:00','8/13/2010' union all
select '104','16:00','8/14/2010' union all
select '101','Off','8/15/2010' union all
select '101','16:00','8/16/2010' union all
select '101','16:00','8/17/2010' union all
select '101','Off','8/18/2010' union all
select '101','16:00','8/19/2010' union all
select '101','18:00','8/20/2010' union all
select '101','16:00','8/21/2010' union all
select '102','Off','8/15/2010' union all
select '102','Offs','8/16/2010' union all
select '102','16:00','8/17/2010' union all
select '102','Off','8/18/2010' union all
select '102','16:00','8/19/2010' union all
select '102','18:00','8/20/2010' union all
select '102','16:00','8/21/2010' union all
select '103','Off','8/15/2010' union all
select '103','16:00','8/16/2010' union all
select '103','16:00','8/17/2010' union all
select '103','Off','8/18/2010' union all
select '103','16:00','8/19/2010' union all
select '103','18:00','8/20/2010' union all
select '103','16:00','8/21/2010' union all
select '104','Off','8/15/2010' union all
select '104','16:00','8/16/2010' union all
select '104','16:00','8/17/2010' union all
select '104','16:00','8/18/2010' union all
select '104','Off','8/19/2010' union all
select '104','18:00','8/20/2010' union all
select '104','16:00','8/21/2010' union all
select '101','Off','8/22/2010' union all
select '101','17:00','8/23/2010' union all
select '101','17:00','8/24/2010' union all
select '101','17:00','8/25/2010' union all
select '101','17:00','8/26/2010' union all
select '101','17:00','8/27/2010' union all
select '101','17:00','8/28/2010' union all
select '102','17:00','8/22/2010' union all
select '102','off','8/23/2010' union all
select '102','17:00','8/24/2010' union all
select '102','17:00','8/25/2010' union all
select '102','17:00','8/26/2010' union all
select '102','17:00','8/27/2010' union all
select '102','17:00','8/28/2010' union all
select '103','Off','8/22/2010' union all
select '103','16:00','8/23/2010' union all
select '103','16:00','8/24/2010' union all
select '103','Off','8/25/2010' union all
select '103','16:00','8/26/2010' union all
select '103','18:00','8/27/2010' union all
select '103','16:00','8/28/2010' union all
select '104','17:00','8/22/2010' union all
select '104','15:00','8/23/2010' union all
select '104','15:00','8/24/2010' union all
select '104','15:00','8/25/2010' union all
select '104','Off','8/26/2010' union all
select '104','17:00','8/27/2010' union all
select '104','17:00','8/28/2010'
1 945
This code will count how many an employee took the day off per day (not date)... -
-
with Testing1 (empno,MatchingOff,atnDate)
-
as
-
(
-
select '101','Off','8/1/2010' union all
-
select '101','17:00','8/2/2010' union all
-
select '101','17:00','8/3/2010' union all
-
select '101','17:00','8/4/2010' union all
-
select '101','17:00','8/5/2010' union all
-
select '101','17:00','8/6/2010' union all
-
select '101','17:00','8/7/2010' union all
-
select '102','17:00','8/1/2010' union all
-
select '102','off','8/2/2010' union all
-
select '102','17:00','8/3/2010' union all
-
select '102','17:00','8/4/2010' union all
-
select '102','17:00','8/5/2010' union all
-
select '102','17:00','8/6/2010' union all
-
select '102','17:00','8/7/2010' union all
-
select '103','17:00','8/1/2010' union all
-
select '103','15:00','8/2/2010' union all
-
select '103','15:00','8/3/2010' union all
-
select '103','Off','8/4/2010' union all
-
select '103','17:00','8/5/2010' union all
-
select '103','17:00','8/6/2010' union all
-
select '103','17:00','8/7/2010' union all
-
select '104','17:00','8/1/2010' union all
-
select '104','15:00','8/2/2010' union all
-
select '104','15:00','8/3/2010' union all
-
select '104','15:00','8/4/2010' union all
-
select '104','Off','8/5/2010' union all
-
select '104','17:00','8/6/2010' union all
-
select '104','17:00','8/7/2010' union all
-
select '101','Off','8/8/2010' union all
-
select '101','16:00','8/9/2010' union all
-
select '101','16:00','8/10/2010' union all
-
select '101','Off','8/11/2010' union all
-
select '101','16:00','8/12/2010' union all
-
select '101','18:00','8/13/2010' union all
-
select '101','16:00','8/14/2010' union all
-
select '102','Off','8/8/2010' union all
-
select '102','Off','8/9/2010' union all
-
select '102','16:00','8/10/2010' union all
-
select '102','Off','8/11/2010' union all
-
select '102','16:00','8/12/2010' union all
-
select '102','18:00','8/13/2010' union all
-
select '102','16:00','8/14/2010' union all
-
select '103','Off','8/8/2010' union all
-
select '103','16:00','8/9/2010' union all
-
select '103','16:00','8/10/2010' union all
-
select '103','Off','8/11/2010' union all
-
select '103','16:00','8/12/2010' union all
-
select '103','18:00','8/13/2010' union all
-
select '103','16:00','8/14/2010' union all
-
select '104','Off','8/8/2010' union all
-
select '104','16:00','8/9/2010' union all
-
select '104','16:00','8/10/2010' union all
-
select '104','17:00','8/11/2010' union all
-
select '104','Off','8/12/2010' union all
-
select '104','18:00','8/13/2010' union all
-
select '104','16:00','8/14/2010' union all
-
select '101','Off','8/15/2010' union all
-
select '101','16:00','8/16/2010' union all
-
select '101','16:00','8/17/2010' union all
-
select '101','Off','8/18/2010' union all
-
select '101','16:00','8/19/2010' union all
-
select '101','18:00','8/20/2010' union all
-
select '101','16:00','8/21/2010' union all
-
select '102','Off','8/15/2010' union all
-
select '102','Offs','8/16/2010' union all
-
select '102','16:00','8/17/2010' union all
-
select '102','Off','8/18/2010' union all
-
select '102','16:00','8/19/2010' union all
-
select '102','18:00','8/20/2010' union all
-
select '102','16:00','8/21/2010' union all
-
select '103','Off','8/15/2010' union all
-
select '103','16:00','8/16/2010' union all
-
select '103','16:00','8/17/2010' union all
-
select '103','Off','8/18/2010' union all
-
select '103','16:00','8/19/2010' union all
-
select '103','18:00','8/20/2010' union all
-
select '103','16:00','8/21/2010' union all
-
select '104','Off','8/15/2010' union all
-
select '104','16:00','8/16/2010' union all
-
select '104','16:00','8/17/2010' union all
-
select '104','16:00','8/18/2010' union all
-
select '104','Off','8/19/2010' union all
-
select '104','18:00','8/20/2010' union all
-
select '104','16:00','8/21/2010' union all
-
select '101','Off','8/22/2010' union all
-
select '101','17:00','8/23/2010' union all
-
select '101','17:00','8/24/2010' union all
-
select '101','17:00','8/25/2010' union all
-
select '101','17:00','8/26/2010' union all
-
select '101','17:00','8/27/2010' union all
-
select '101','17:00','8/28/2010' union all
-
select '102','17:00','8/22/2010' union all
-
select '102','off','8/23/2010' union all
-
select '102','17:00','8/24/2010' union all
-
select '102','17:00','8/25/2010' union all
-
select '102','17:00','8/26/2010' union all
-
select '102','17:00','8/27/2010' union all
-
select '102','17:00','8/28/2010' union all
-
select '103','Off','8/22/2010' union all
-
select '103','16:00','8/23/2010' union all
-
select '103','16:00','8/24/2010' union all
-
select '103','Off','8/25/2010' union all
-
select '103','16:00','8/26/2010' union all
-
select '103','18:00','8/27/2010' union all
-
select '103','16:00','8/28/2010' union all
-
select '104','17:00','8/22/2010' union all
-
select '104','15:00','8/23/2010' union all
-
select '104','15:00','8/24/2010' union all
-
select '104','15:00','8/25/2010' union all
-
select '104','Off','8/26/2010' union all
-
select '104','17:00','8/27/2010' union all
-
select '104','17:00','8/28/2010'
-
)
-
select
-
empno, datename(dw,atnDate), count(*)
-
from Testing1
-
where MatchingOff = 'Off'
-
group by empno, datename(dw,atnDate)
-
order by 1
-
-
The CTE is for code testing purposes only...
You can start from here...
Happy Coding!!!
~~ CK
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jenn L |
last post by:
I have a database that is pre-populated with sequential part numbers.
As people reserve the parts I update a flag to show the # is no longer
available. Now they want the ability to take out a...
|
by: Max Harvey |
last post by:
Hi,
I have looked at the example called "Open Parameter queries from code"
from the site http://www.mvps.org/access/queries/qry0003.htm
I made up a test which I though looked pretty close...
|
by: deko |
last post by:
I'm trying to update the address record of an existing record in my mdb with
values from another existing record in the same table. In pseudo code it
might look like this:
UPDATE tblAddress SET...
|
by: Brian |
last post by:
Hello,
Basically, I'm running a query on a form's activation, and I'd like to
have the results of the query be placed into other fields on the same
form automatically.
Does anybody know how...
|
by: phlype.johnson |
last post by:
I'm struggling to find the best query from performance point of view
and readability for a normalized DB design.
To illustrate better my question on whether normalized designs lead to
more complex...
|
by: mike |
last post by:
Hello,
I am new to XPATH and am having a hard time selecting some nodes.
I want to select all the record nodes where Status = 'Unprocessed' or
'Queued' (that part I can get) but additionally I...
|
by: RCapps |
last post by:
When running the below SQL Query I keep getting the following error:
Server: Msg 4924, Level 16, State 1, Line 1
ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
|
by: rupinderbatra |
last post by:
Hello Everyone,
I have a table with the following structure:
Employee ID, Salary.
I want to find employees with top 5% salaries.
Appreciate if someone may please help.
|
by: zachster17 |
last post by:
Hi everyone,
First of all, sorry for the massive amount of SQL I am about to type. I have a database that has a "lives" table of insured employees and then another table (that links to the lives...
|
by: Dinesh |
last post by:
Hi experts,
I am working on SQL Server 2005.
Now i have to write a query which will extract some information from a
table.
My main table is having few columns supose 3 columns.
EmpID ...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |