首页 > 解决方案 > 在 View SQL server 中分组

问题描述

这是我创建的视图:

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获取id`。answers``forf every

我尝试了太多解决方案但没有输出

标签: sql-servergroup-bygroupingsql-view

解决方案


推荐阅读