If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > SQL Help - combining tables and Count Distinct

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-29-12, 08:22
Perilous Perilous is offline
Registered User
 
Join Date: May 2012
Posts: 4
SQL Help - combining tables and Count Distinct

I'm new to SQL and I'm learning as I go so forgive me if i'm asking a stupid question but I'm currently using a database for quality monitoring and there are 3 separate tables, each of them have their own marking criteria etc.
Regardless of the differences between the 3 tables marking criteria they do however all share the same GRADE choices at the end, I'm now trying to create a report which combines all 3x tables results and counts the Grades etc.

Problem 1:
I need to incorporate another column that counts the Unique advisors. I know this SQL works if i put it in a separate query:
SELECT Count(*) AS [UNIQUE ADVISORS]
FROM
(SELECT DISTINCT AdvisorName FROM CalcCarelineRQM) AS T;

but I don't know how to mix a SELECT DISTINCT inside of the rest of the SQL (below)

Problem 2:
This SQL works for the CalcCarelineRQM table, but i now don't know how I can combine the other tables results into the same query, preferably keeping the same Grouping level?

My 3 tables:
CalcCarelineRQM
CalcOrderlineRQM
CalcNumeroRQM

My SQL so far:

SELECT CalcCarelineRQM.TeamManagerName,
Round(Avg([CalcCarelineRQM].Percentage),2) AS [AVRGE CARELINE SCORE],
Count(CalcCarelineRQM.UserID) AS [VOL CALLS MONTD],
Sum(IIf(([CalcCarelineRQM].Classification)="Excellent Customer Service",1,0)) AS [EXCELLENT CUS SERV],
Sum(IIf(([CalcCarelineRQM].Classification)="Good Customer Service",1,0)) AS [GOOD CUS SERV],
Sum(IIf(([CalcCarelineRQM].Classification)="Customer Service Needs Improvement",1,0)) AS [CUS SERV NEEDS IMPRMNT],
Sum(IIf(([CalcCarelineRQM].Classification)="Business Rules Need Improvement",1,0)) AS [BUS RULE REQS IMPRMNT],
Sum(IIf(([CalcCarelineRQM].Classification)="Customer Service is Poor (not a 1st time fix)",1,0)) AS [POOR CUS SERV],
Sum(IIf(([CalcCarelineRQM].FirstTimeFix)="YES",1,0)) AS [FTF YES],
Sum(IIf(([CalcCarelineRQM].FirstTimeFix)="NO",1,0)) AS [FTF NO],
Round([FTF YES]/([FTF YES]+[FTF NO]),4)*100 AS [FTF %]
FROM CalcCarelineRQM
GROUP BY CalcCarelineRQM.TeamManagerName;


Please could someone help me
Reply With Quote
  #2 (permalink)  
Old 06-30-12, 09:58
canupus canupus is offline
Registered User
 
Join Date: Jul 2004
Location: South Dakota
Posts: 255
Ok so I'm not sure that I completely understand what you are asking but I'm going to take a stab at it.

Problem #2:
I'm guessing that you want to do a similar query on the other 2 tables like you have for the CalcCareLineRQM table. I would probably have 3 separate queries (1 for each table) and then do a UNION to join them all into one result.

Problem #1:
If it works in a separate query have you tried adding that query to the first query and use a join between the two? You will need to some how relate the data to the main query otherwise you will get the same number of Advisors for each row that is returned from the main query.

C
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On