Query problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've the following query:
SELECT agentsq.Agent, Count(tasks.DR) AS CountOfDR, Count(tasks.MA) AS
CountOfMA, Count(tasks.SHM) AS CountOfSHM, Count(tasks.NA) AS CountOfNA,
Count(tasks.SH) AS CountOfSH
FROM agentsq LEFT JOIN tasks ON (agentsq.Agent = tasks.NA) AND
(agentsq.Agent = tasks.SHM) AND (agentsq.Agent = tasks.MA) AND (agentsq.Agent
= tasks.DR) AND (agentsq.Agent = tasks.SH)
GROUP BY agentsq.Agent;
But actually the COUNT function does not count the rows where (for
example) agent X did the DR task 3 times...
cAN ANYBODY HELP?
 
Hi Pietro,

I am guessing your tasks table is not normalized. Your query demands
agentsq.Agent == tasks.Agent on every row of tasks across four
columns. This suggests DR, MA, SHM and NA are in fact independent
measures of Agent?

If I am right, you should decompose tasks into four tables, one each
for DR, MA, SHM and SH measures. This being the case then you can join
agentsq to each of the four tables and get correct counts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top