需要有关如何使用以下模式使EmailId成为具有JSON路径表达式的EventId子数组的指导:
答案 0 :(得分:0)
你可以使用它。
DECLARE @PatientId INT = 1
SELECT Event.*, RE.EmailId
FROM ( SELECT DISTINCT
E.EventId,
E.StartDate,
E.EndDate,
E.IsRecurring,
MRP.RecurringPatternId,
MRP.MedicationId,
PMR.PatientId
FROM
Event E
INNER JOIN MedicationRecurringPattern MRP ON E.EventId = MRP.EventId
INNER JOIN PatientMedicationReminders PMR ON E.EventId = PMR.EventId
WHERE
PMR.PatientId = @PatientId
) Event
LEFT JOIN ReminderEmails RE ON Event.EventId = RE.EVentId
LEFT JOIN Email ON RE.EmailId = Email.EmailId
FOR JSON AUTO