I've inherited a database system designed to calculate sickness absence statistics. There is a main table with an employee ID [EMPLOYEEID] which also holds the number of days worked by that person in a year [thedaysworked]. There is then a table which records absences for each employee, it records the date of the absence etc and also holds the number of days absent [Number_of_days_ absent]. Each time the employee is absent they will have an entry in this table linked by [EMPLOYEEID]. I have created a query which needs to total all these absence days, which works fine, however, what i need is to then total these by school and section for absences within the last year, i have also got this working without much effort. -
-
SELECT School.[Type Description] AS School, Section.[Type Description] AS [Section], Sum(absence.Working_Days_Absent) AS [Working Days of Absence]
-
FROM [Employee Status] INNER JOIN ([Section] INNER JOIN (School INNER JOIN (Role INNER JOIN (KCSTAFF02 INNER JOIN absence ON KCSTAFF02.EMPLOYEEID = absence.employeeID) ON Role.RoleID = KCSTAFF02.ABSENCE_Role) ON School.School = KCSTAFF02.ABSENCE_School) ON Section.Section = KCSTAFF02.ABSENCE_Section) ON [Employee Status].[Employee Status] = KCSTAFF02.ABSENCE_Status
-
WHERE (((absence.[1st_day_of_absence])>Date()-365))
-
GROUP BY School.[Type Description], Section.[Type Description];
-
The problem arises when i ask it to work out how many people are in each school and section. I asked it to count [EMPLOYEEID] from the main table but this results in this ID being counted for each entry in the absence table, which results in a lot more people than expected! I also have the same problem with [thedaysworked] which adds itself for each entry in the absence databse, so if an employee has 5 absences this gets counted 5 times.Is there a way i can tell it just to count it once but still leave the other totals which are working alone?
This is what i currently have -
-
SELECT School.[Type Description] AS School, Section.[Type Description] AS [Section], Sum(KCSTAFF02.thedaysworked) AS [Combined Days], Count(KCSTAFF02.EMPLOYEEID) AS [Employee Count], Sum(absence.Number_of_Days_Absent) AS [Days of Absence], Sum(absence.Working_Days_Absent) AS [Working Days of Absence]
-
FROM [Employee Status] INNER JOIN ([Section] INNER JOIN (School INNER JOIN (Role INNER JOIN (KCSTAFF02 INNER JOIN absence ON KCSTAFF02.EMPLOYEEID = absence.employeeID) ON Role.RoleID = KCSTAFF02.ABSENCE_Role) ON School.School = KCSTAFF02.ABSENCE_School) ON Section.Section = KCSTAFF02.ABSENCE_Section) ON [Employee Status].[Employee Status] = KCSTAFF02.ABSENCE_Status
-
WHERE (((absence.[1st_day_of_absence])>Date()-365))
-
GROUP BY School.[Type Description], Section.[Type Description];
-
1 2606 Rabbit 12,516
Recognized Expert Moderator MVP
You won't be able to do both a unique count and a non-unique in the same query.
You'll have to separate them. And to do a unique count, you'll need to do a SELECT DISTINCT first.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DH |
last post by:
Say I have a table with two columns that matter to this example,
and . And here is an example of what the rows
currently look like:
,
1,6/27/2001
1,6/27/2001
1,5/31/2001
2,6/27/2001
2,6/30/2001
|
by: Riley DeWiley |
last post by:
I am continually amazed by SQL's ability to humble me ....
I have a toy query into a toy database that looks just like this:
SELECT .
FROM f, fw, w
WHERE f.id = fw.fid and fw.wid = w.id and w.id in (((((select distinct w.id
from w where w.x in ('a', 'b') )))))
GROUP BY .
HAVING count(f.id) = (select count(id) from (((((select distinct w.id from w
|
by: Robert |
last post by:
I am trying to create a db for service providers by county. I'm relatively
new to db programming, but I have done quite a bit of programming ranging
from the old basic days up to doing some programming in the HotDocs
software. I've kind of accomplished my goal in access, but I'm not quite
there yet and figure I've really screwed something up.
The db consists of 5 tables I believe. T1 is the main contact info, with an
autonumber ID...
|
by: rdnews |
last post by:
Dear group,
I got excellent help here a while back in optimizing a slow query, so I
thought I'd try again with another one...
I have a small table, around 3000 rows with two columns. One is a
timestamp and the other is an integer. Each day, a number of entries
are created, with integers ranging from 1 to 5.
I need to find how many entries with the integer of 3 are created per
|
by: xhenxhe |
last post by:
I'm wondering if something like this can be done in mysql...
I have two tables I want to pull data from. One table will contain a
unique user_id which I could pull out like:
select user_id from table;
that's basically all I would need from that table. The second table
contains a user id field, but can have several duplicate user_id's in
the table. Essentially I would need:
| |
by: Dixie |
last post by:
I have asked this question before, but I could not get the suggested
solution work. So I will give more details this time.
I have an append query that adds several hundred records to a table into a
text field. Next to this text field is a separate Number (Single) field
with a unique ID number for the entry. I want each number to be 1 more than
the previous entry's number to keep it unique (I don't want autonumbering
for this, as I...
|
by: funky |
last post by:
hello,
I've got a big problem ad i'm not able to resolve it. We have a server
running oracle 10g version 10.1.0. We usually use access as front end
and connect database tables for data extraction. We have been using
oracle client 10.1.0.2 with it's odbc for a while without problem. The
problem arose when we decided to reconnect all the tables and save
password. Some query became suddenly very slow. Then I've discovered
that the tables...
|
by: jameswilkinsonfjs |
last post by:
Hi All,
Ok I have a table - it lists items with a unique reference
code; lets say there are 4 items :
Item RefCode
1 ABC1
2 ABC2
3 ABC3
4 ABC4
|
by: escapersky |
last post by:
I have a database that i've been entering and I need to show how many unique entries I have entered prividing the date range.
The database includes date, productID, locationID, quantity etc.
What I'm trying to find out is the numbers of lines that is Unique date AND locationID. LocationID's are 4 digits with alphabets/number mixed.
I've looked around and only found query unique entries for 1 select field.
I have Access 2007 at work...
|
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,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |