Filter a query by date in another table?

N

Noozer

I have the following query...

SELECT GrpDesc, CatDesc, IssueDesc, x.EntryCount
FROM [SELECT IssIDLink, COUNT(*) AS EntryCount FROM Entries GROUP BY
IssIDLink]. AS x INNER JOIN
(Issues INNER JOIN
(Categories INNER JOIN
Groups ON Categories.GroupIDLink=Groups.GroupID
) ON Issues.CatIDLink=Categories.CatID
) ON x.IssIDLink=Issues.IssueID
ORDER BY x.EntryCount DESC;

....which returns how many times a particular Entry occurs, with a
description of the Issue, the Category to which the issue belongs and the
Group to which that category belongs. It works well.

I want to be able to filter the results so that only Entries occuring
between specific dates are counted. The Entries table is linked to both the
Issues table and the Calls table. It is the Calls table the contains the
field Submitted that holds the date that the Entry was made. The query below
does not work, but gives an idea as to what I am trying to accomplish

SELECT GrpDesc, CatDesc, IssueDesc, x.EntryCount
FROM Calls INNER JOIN Entries ON Calls.CallID=Entries.CallIDLink ,
[SELECT IssIDLink, COUNT(*) AS EntryCount FROM Entries GROUP BY
IssIDLink]. AS x INNER JOIN
(Issues INNER JOIN
(Categories INNER JOIN
Groups ON Categories.GroupIDLink=Groups.GroupID
) ON Issues.CatIDLink=Categories.CatID
) ON x.IssIDLink=Issues.IssueID
WHERE Submitted >= #2005-01-13# AND Submitted <= #2005-01-31#
ORDER BY x.EntryCount DESC;

My tables:

Groups
GroupID - autonumber
GrpDesc - text
Categories
CatID - autonumber
CatDesc - text
GrpIDLink - number (link to Group.GroupID - Many Categories to one Groups)

Issues
IssueID - autonumber
IssDesc - text
CatIDLink - number (link to Category.CatID - Many Issues to one
Categories)

Calls
CallID - autonumber
IP - text
Submitted - date/time

Entries
CallIDLink - number (link to Call.CallID - Many Entries to one Calls)
IssIDLink - number (link to Issue.IssID - Many Entries to one Issues)
Entry- text
EntryText - Yes/No


....any help out there?
 
N

Noozer

I want to be able to filter the results so that only Entries occuring
between specific dates are counted. The Entries table is linked to both the
Issues table and the Calls table. It is the Calls table the contains the
field Submitted that holds the date that the Entry was made.

....and I figured out how to accomplish my task. Hope this helps someone else
out. Let me know if I've made this more complicated than necessary.

SELECT GrpDesc, CatDesc, IssueDesc, x.EntryCount AS EntryCount
FROM (SELECT IssIDLink, COUNT(*) AS EntryCount
FROM ( SELECT IssIDLink
FROM (Entries INNER JOIN Calls ON Entries.CallIDLink = Calls.CallID)
WHERE Calls.Submitted >#2005-01-01# AND Calls.Submitted <#2005-01-24#
)
GROUP BY IssIDLink
)
AS x INNER JOIN (
Issues INNER JOIN (
Categories INNER JOIN Groups ON Categories.GroupIDLink=Groups.GroupID
) ON Issues.CatIDLink=Categories.CatID
)
ON x.IssIDLink=Issues.IssueID
ORDER BY GrpOrder, CatOrder, IssueOrder;
 

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

Top