ReporterTbl
有一個與AttachmentTbl
一對多的關係。如何計算一對多的關係
在ReporterTbl
,我有一個ID(101),我可以有ReporterTbl.Id
SELECT
ISNULL(ReporterTbl.Id, 0) AS Id,
CONVERT(char(10), ReporterTbl.StartDate, 101) AS StartDate,
ISNULL(ReporterTbl.PriorityId, 0) AS PriorityId,
ISNULL(dbo.ReporterTbl.PriorityDesc, '') AS PriorityDesc,
(select
ReporterTbl.Id,
COUNT(dbo.AttachmentTbl.Id) AS attachment_Id
FROM
dbo.AttachmentTbl RIGHT OUTER JOIN
ReporterTbl ON dbo.AttachmentTbl.Id = ReporterTbl.Id
GROUP BY ReporterTbl.Id) AS IsAttachment
)
基本上,我想知道有關AttachmentTbl
多個Attachment
s的給出ReporterTbl.ID
,多少Attachment
小號我有嗎?
表結構:
ReporterTbl
Id int {**PrimaryKey**}
StartDate datetime
PriorityId int
PriorityDesc varchar(500
AttachmentTbl:
AttachmentId indentity
Id {**FK to ReproterTbl**}
Filename
Content
...
當然,如果你想要一個記者。 – 2010-09-09 19:20:23
但這就是他要求的.... – 2010-09-09 19:21:18