简体   繁体   中英

Access 2007 Left Join doesn't work

I have 2 tables. Table 1 is tbl_DaysWeeksMonths which has one row for each date and it's corresponding Week Ending date and calendar month. Table 2 is tbl_CallStats which shows one record per agent per day with their corresponding call counts and stats etc. Not all consultants have records for every day of the week.

To the left is Table 1 (tbl_DaysWeeksMonths) with columns Date, Week Ending, Month. To the right is Table 2 (tbl_CallStats) with columns row_date, agent, logid, total calls, talk time.

I want to link the tbl_CallStats to tbl_DaysWeeksMonths so that a date record is displayed for each agent (based on tbl_DaysWeeksMonths) even if they didn't take calls on a particular day.

I've tried to do a Left join but it still only displays records for days where calls were taken. I feel like I'm missing something simple here. Please help.

SELECT Date,[Week Ending],tbl_CallStats.agent
FROM tbl_DaysWeeksMonths
LEFT JOIN tbl_CallStats
ON tbl_DaysWeeksMonths.Date = tbl_CallStats.row_date
GROUP BY Date, Week, agent

this query gets all the days and should show all the agent call that are in the tbl_CallStats. This takes in consideration that there will always be a row in tbl_CallStats for a each day and agent.

"select tbl_DaysWeeksMonths.Date, tbl_DaysWeeksMonths.WeekEnding, tbl_DaysWeeksMonths.Month, 
tbl_CallStats.agent, tbl_CallStats.logid, tbl_CallStats.totalcalls, tbl_CallStats.talktime
from tbl_DaysWeeksMonths
left join tbl_CallStats on tbl_CallStats.row_date = tbl_DaysWeeksMonths.Date
group by tbl_CallStats.agent, tbl_DaysWeeksMonths.Date "

If you simply do not have a record in tbl_CallStats when there is no calls maybe you can have another table for the agents and get the values related to them, like, select all days joining all agents for each day and left join to the callstats...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM