查询计算每位研究人员提交的总数

时间:2015-09-08 09:41:24

标签: mysql sql count

我有3个与提交和研究员有关的表。

提交表:

SubmissionID, Type, Title, Status, Comment, CapturedOnRIMS, NumberOfAuthors, NumberOfWitsAuthors, TotalPages, PagesInPreamble, PagesInText, NumberOfChapters, Location, PublicationID, CESMID, SubmissionDate

研究员表:

ResearcherID, FirstName, Surname, RegistrationDate, QualificationType, JobName, Availability, SchoolID

ResearcherSubmission(关系表):

SubmissionID, ResearcherID

我正在尝试创建一个查询,显示每位研究人员提交的总数。研究人员可以提交许多文章,许多研究人员可以提交提交,因此可以进行关系表。

期望的输出:

Name             Number of Submission
John Doe                   14
William Smith              10
Ellie Carter               12
Susan Wright               10

1 个答案:

答案 0 :(得分:1)

只需JOIN表并执行group by

select r.FirstName, r.LastName, count(*) as no_of_sub
from Researcher r
  join ResearcherSubmission rs on r.ResearcherID = rs.ResearcherID
  join Submission s on s.SubmissionID = rs.SubmissionID
group by r.FirstName, r.LastName