473,418 Members | 4,041 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,418 software developers and data experts.

query to find out no of employees who are getting weekOff on sameday

45
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'
Oct 18 '10 #1
1 945
ck9663
2,878 Expert 2GB
This code will count how many an employee took the day off per day (not date)...

Expand|Select|Wrap|Line Numbers
  1.  
  2. with Testing1 (empno,MatchingOff,atnDate)
  3. as
  4. (
  5. select '101','Off','8/1/2010' union all
  6. select '101','17:00','8/2/2010' union all
  7. select '101','17:00','8/3/2010' union all
  8. select '101','17:00','8/4/2010' union all
  9. select '101','17:00','8/5/2010' union all
  10. select '101','17:00','8/6/2010' union all
  11. select '101','17:00','8/7/2010' union all
  12. select '102','17:00','8/1/2010' union all
  13. select '102','off','8/2/2010' union all
  14. select '102','17:00','8/3/2010' union all
  15. select '102','17:00','8/4/2010' union all
  16. select '102','17:00','8/5/2010' union all
  17. select '102','17:00','8/6/2010' union all
  18. select '102','17:00','8/7/2010' union all
  19. select '103','17:00','8/1/2010' union all
  20. select '103','15:00','8/2/2010' union all
  21. select '103','15:00','8/3/2010' union all
  22. select '103','Off','8/4/2010' union all
  23. select '103','17:00','8/5/2010' union all
  24. select '103','17:00','8/6/2010' union all
  25. select '103','17:00','8/7/2010' union all
  26. select '104','17:00','8/1/2010' union all
  27. select '104','15:00','8/2/2010' union all
  28. select '104','15:00','8/3/2010' union all
  29. select '104','15:00','8/4/2010' union all
  30. select '104','Off','8/5/2010' union all
  31. select '104','17:00','8/6/2010' union all
  32. select '104','17:00','8/7/2010' union all
  33. select '101','Off','8/8/2010' union all
  34. select '101','16:00','8/9/2010' union all
  35. select '101','16:00','8/10/2010' union all
  36. select '101','Off','8/11/2010' union all
  37. select '101','16:00','8/12/2010' union all
  38. select '101','18:00','8/13/2010' union all
  39. select '101','16:00','8/14/2010' union all
  40. select '102','Off','8/8/2010' union all
  41. select '102','Off','8/9/2010' union all
  42. select '102','16:00','8/10/2010' union all
  43. select '102','Off','8/11/2010' union all
  44. select '102','16:00','8/12/2010' union all
  45. select '102','18:00','8/13/2010' union all
  46. select '102','16:00','8/14/2010' union all
  47. select '103','Off','8/8/2010' union all
  48. select '103','16:00','8/9/2010' union all
  49. select '103','16:00','8/10/2010' union all
  50. select '103','Off','8/11/2010' union all
  51. select '103','16:00','8/12/2010' union all
  52. select '103','18:00','8/13/2010' union all
  53. select '103','16:00','8/14/2010' union all
  54. select '104','Off','8/8/2010' union all
  55. select '104','16:00','8/9/2010' union all
  56. select '104','16:00','8/10/2010' union all
  57. select '104','17:00','8/11/2010' union all
  58. select '104','Off','8/12/2010' union all
  59. select '104','18:00','8/13/2010' union all
  60. select '104','16:00','8/14/2010' union all
  61. select '101','Off','8/15/2010' union all
  62. select '101','16:00','8/16/2010' union all
  63. select '101','16:00','8/17/2010' union all
  64. select '101','Off','8/18/2010' union all
  65. select '101','16:00','8/19/2010' union all
  66. select '101','18:00','8/20/2010' union all
  67. select '101','16:00','8/21/2010' union all
  68. select '102','Off','8/15/2010' union all
  69. select '102','Offs','8/16/2010' union all
  70. select '102','16:00','8/17/2010' union all
  71. select '102','Off','8/18/2010' union all
  72. select '102','16:00','8/19/2010' union all
  73. select '102','18:00','8/20/2010' union all
  74. select '102','16:00','8/21/2010' union all
  75. select '103','Off','8/15/2010' union all
  76. select '103','16:00','8/16/2010' union all
  77. select '103','16:00','8/17/2010' union all
  78. select '103','Off','8/18/2010' union all
  79. select '103','16:00','8/19/2010' union all
  80. select '103','18:00','8/20/2010' union all
  81. select '103','16:00','8/21/2010' union all
  82. select '104','Off','8/15/2010' union all
  83. select '104','16:00','8/16/2010' union all
  84. select '104','16:00','8/17/2010' union all
  85. select '104','16:00','8/18/2010' union all
  86. select '104','Off','8/19/2010' union all
  87. select '104','18:00','8/20/2010' union all
  88. select '104','16:00','8/21/2010' union all
  89. select '101','Off','8/22/2010' union all
  90. select '101','17:00','8/23/2010' union all
  91. select '101','17:00','8/24/2010' union all
  92. select '101','17:00','8/25/2010' union all
  93. select '101','17:00','8/26/2010' union all
  94. select '101','17:00','8/27/2010' union all
  95. select '101','17:00','8/28/2010' union all
  96. select '102','17:00','8/22/2010' union all
  97. select '102','off','8/23/2010' union all
  98. select '102','17:00','8/24/2010' union all
  99. select '102','17:00','8/25/2010' union all
  100. select '102','17:00','8/26/2010' union all
  101. select '102','17:00','8/27/2010' union all
  102. select '102','17:00','8/28/2010' union all
  103. select '103','Off','8/22/2010' union all
  104. select '103','16:00','8/23/2010' union all
  105. select '103','16:00','8/24/2010' union all
  106. select '103','Off','8/25/2010' union all
  107. select '103','16:00','8/26/2010' union all
  108. select '103','18:00','8/27/2010' union all
  109. select '103','16:00','8/28/2010' union all
  110. select '104','17:00','8/22/2010' union all
  111. select '104','15:00','8/23/2010' union all
  112. select '104','15:00','8/24/2010' union all
  113. select '104','15:00','8/25/2010' union all
  114. select '104','Off','8/26/2010' union all
  115. select '104','17:00','8/27/2010' union all
  116. select '104','17:00','8/28/2010' 
  117. )
  118. select 
  119. empno, datename(dw,atnDate), count(*)
  120. from Testing1 
  121. where MatchingOff = 'Off' 
  122. group by empno, datename(dw,atnDate)
  123. order by 1
  124.  
  125.  
The CTE is for code testing purposes only...

You can start from here...

Happy Coding!!!

~~ CK
Oct 18 '10 #2

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

Similar topics

6
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...
4
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...
4
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...
6
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...
0
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...
3
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...
0
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...
4
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.
5
zachster17
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...
2
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 ...
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
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
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,...

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.