Группировать по серверу View SQL - PullRequest
0 голосов
/ 11 марта 2020

Вот представление, которое я создал:

CREATE VIEW V_EventAnswers
AS
    SELECT ISNULL(ROW_NUMBER() OVER (ORDER BY e.id DESC), -1) AS RowID,
           ISNULL(Questionid, QuestionUniqueId) AS Questionid,
           QuestionUniqueId,
           QuestionNameAr,
           QuestionNameEn,
           QuestionType,
           SectionId,
           QuestionFieldOrder,
           QuestionAnswers,
           IsIssue,
           QuestionUnit,
           ReadinessIndicator,
           e.id AS EventId,
           e.SubmitionDate,
           e.Location,
           e.TenantId
    FROM EventDetails D
         CROSS APPLY
        OPENJSON(D.SubmittedJSONDATA)
            WITH (questions nvarchar(MAX) '$.fields' AS json) AS jsonValues
         OUTER APPLY
        openjson(questions)
            WITH (IsIssue bit '$.issue',
                  QuestionUnit int '$.responsibleUnit',
                  QuestionUniqueId nvarchar(100) '$.id',
                  Questionid nvarchar(100) '$.templateQuestionId',
                  QuestionNameAr nvarchar(100) '$.arLabel',
                  QuestionNameEn nvarchar(100) '$.enLabel',
                  QuestionType nvarchar(100) '$.controlType',
                  SectionId nvarchar(100) '$.sectionId',
                  QuestionFieldOrder int '$.fieldOrder',
                  ReadinessIndicator int '$.readinessIndicator',
                  answers nvarchar(MAX) '$.values' AS json) AS jsonAnswers
         OUTER APPLY
        openjson(answers)
            WITH (QuestionAnswers nvarchar(MAX) '$')
         INNER JOIN EVENT E ON E.id = D.EventId;
GO

Мне нужно сгруппировать часть questions по '$.id' и EventId, чтобы получить answers``forf every id` в списке через запятую.

Я пробовал слишком много решений, но без вывода

...