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

query that counts from 3 fields

18
I have a data base that keeps track of incident reports. There may be 1, 2, or 3 staff involved in an incident. There are fields [staff 1], [staff 2], and [staff 3] in one table. A staff name may show up in any of the 3 fields. I have queries that show staff count in each field. The question is how do get one total, ie

Smith is in [Staff 1] 3 times, [Staff 2] 1 time, and [Staff 3] 2 times for a total of 6.
Jones is in [Staff 1] 10 times, [Staff 2] 6 time, and [Staff 3] 4 times for a total of 20.
And so on.

How do I make this happen?
Aug 24 '09 #1
5 1509
ajalwaysus
266 Expert 100+
I think that the solution to this is much more complicated than if you had a Staff table that you could assign staff to an incident report.

Example:
[Incident ID] [Staff Mamber]
1 Jones
1 Smith
2 Smith
3 Jones
3 Smith
4 Jones
5 Jones
6 Smith

-AJ
Aug 24 '09 #2
pld60
18
I may not have been clear. Each record in the table is an incident. So, if there is an incident report writen only Smith is involved then Smith is entered in the field [Staff 1]. If Smith and Jones are both involve then Smith is entered in the field [Staff 1] and Jones is entered in the field [Staff 2] or Jones is entered in the field [Staff 1] and Smith is entered in the field [Staff 2]. [Staff 1] would be the most involved etc.

If these were the only 2 records then I need a query result that would Count Smith 2, Jones 1.

Hope this helps.
Aug 24 '09 #3
ajalwaysus
266 Expert 100+
I hope someone else may have a better idea but i am drawing a blank, this is the best I could come up with...

Expand|Select|Wrap|Line Numbers
  1. SELECT Staff.Staff1, Count(Staff.Staff1) AS CountOfStaff1, "" AS Staff2, "" AS CountOfStaff2, "" AS Staff3, "" AS CountOfStaff3
  2. FROM Staff
  3. GROUP BY Staff.Staff1
  4. HAVING (((Staff.Staff1) Is Not Null))
  5. UNION ALL
  6. SELECT "" AS Staff1, "" AS CountOfStaff1, Staff.Staff2, Count(Staff.Staff2) AS CountOfStaff2, "" AS Staff3, "" AS CountOfStaff3
  7. FROM Staff
  8. GROUP BY Staff.Staff2
  9. HAVING (((Staff.Staff2) Is Not Null))
  10. UNION ALL SELECT "" AS Staff1, "" AS CountOfStaff1, "" AS Staff2, "" AS CountOfStaff2, Staff.Staff3, Count(Staff.Staff3) AS CountOfStaff3
  11. FROM Staff
  12. GROUP BY Staff.Staff3
  13. HAVING (((Staff.Staff3) Is Not Null));
  14.  
pld60, I understand fully what you are doing, but this does not pass normalization and therefore makes reporting more difficult. You say you need a way of prioritizing staff to the incident ticket then you could design a table like this...

Expand|Select|Wrap|Line Numbers
  1. [Incident ID] [Staff Member] [Priority Rank]
  2.      1             Jones            1
  3.      1             Smith            2
  4.      2             Smith            1
  5.      3             Jones            2
  6.      3             Smith            1
  7.      3             Doe              3
  8.      4             Jones            1
  9.      5             Jones            1
  10.      6             Smith            1
  11.  
Aug 24 '09 #4
pld60
18
Thanks for your help but, this does not work. I do not need away of prioritizing at all, that is done on the incident report when writen and then it is put in the fields accordingly. May be there is not a simple way of doing this?
Aug 24 '09 #5
FishVal
2,653 Expert 2GB
A simple way of doing this is normalization.

Kindest regards,
Fish.
Aug 25 '09 #6

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

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
7
by: jane | last post by:
HI, I was ask to do a query to get the member active condition I had table to show the member number and active status in three month. ACC A1 A2 A3 ---- -----------...
1
by: Robert | last post by:
How can I query an existing table and update a field in each record in the table with the occurrence count of each record e.g. update field to 1 (= first record occurrence), update field to 2 for...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
1
by: sunilkeswani | last post by:
Hi I am still new to access. I want to know how i can build a query which can display results from 4 different columns/fields Like. Field1 Field2 Field3 Field4 1 2 1 ...
1
by: TechnoPup | last post by:
Greetings, I am very new to working with databases, and I am not sure how to go about structuring the query I need. What I have is an Access database with approx. 400,000 records in 5 fields. ...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
28
by: G8tors | last post by:
I have a fantasy football league that I am keeping stats for in an Access Database. I need help coming up with a way to calclulate the winning % for each team for their entire career. What I have...
4
by: LaSalamandra | last post by:
Let us suppose we have this table ID - CITIES 1 New York 2 New York 3 Los Angeles 4 Los Angeles 5 Los Angeles 6 Atlanta 7 Atlanta
2
by: runway27 | last post by:
hi i have an enquiry table which collects information about users making an online travel enquiry the fields in the table are = StoryTitle, EndCity, mode, PricedFrom, numAdults, numChildren,...
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: 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
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,...
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
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.