0

Right now I have two separate queries to achieve the results but I would like one query. I'm using MS Access.

tblJournal          tblArticle      tblStatus
----------          ----------      ---------
JournalID           ArticleID       ID
JournalTitle        JournalCode     StatusName
JournalCode         StatusID       
Cancelled(yes/no)   Date
                    ArticleTitle
                    SignedDate

The query should have:

tblJournal.JournalTitle, 
tblJournal.JournalCode, 
Year([tblArticle].[Date]), 
Count of articles per year which have a tblArticle.SignedDate, 
Count of articles per year with tblStatus.StatusName 'Published' and tblJournal.Cancelled NO.
4

1 に答える 1

1

私はこれがあなたが探しているものであるべきだと思います:

SELECT
  tblJournal.JournalTitle, 
  tblJournal.JournalCode, 
  Year([tblArticle].[Date]),
  Count(tblArticle.SignedDate) as Tot_Articles_Year,
  Sum(IIF((not tblJournal.Cancelled) and (tblStatus.StatusName='Published'),1,0)) as Tot_Published
FROM
  (tblJournal LEFT JOIN tblArticle
   ON tblJournal.JournalCode = tblArticle.JournalCode)
  LEFT JOIN tblStatus
  ON tblArticle.StatusID = tblStatus.ID
GROUP BY 
  tblJournal.JournalTitle, 
  tblJournal.JournalCode, 
  Year([tblArticle].[Date])
于 2012-12-04T13:45:01.477 に答える