0
"Project nr"    "Task"                "Task deadline"  "Task Type Production"

456             pack                  1 april 2013      Pack
456             Leave production      3 april 2013      Leave Production
456             Flight date           9 april 2013      Flight Date

123             pack                  1 april 2013      Pack
123             Leave production      6 april 2013      Leave Production
123             Flight date           9 april 2013      Flight Date

789             pack                  1 april 2013      Pack
789             Leave production      9 april 2013      Leave Production
789             Flight date           9 april 2013      Flight Date

こんにちは、私の現在のクエリの下です。上記のように、3つのグループにとどまるように、休暇の生産時に日付でソートされた3行で表示するにはどうすればよいですか。プロジェクトID番号はグループにとどまる必要があり、グループは休暇の作成時にソートする必要があります。

    SELECT MSP_EpmProject_UserView.[Project nr]
    ,max(CASE WHEN [Task Type Production] = 'Packed' THEN [Task deadline] END) AS Pack
    ,max(CASE WHEN [Task Type Production] = 'Leave Production' THEN [Task deadline]
    END) AS [Leave Production]
    ,max(CASE WHEN [Task Type Production] = 'Flight Date' THEN [Task deadline]
    END) AS [Flight Date]

    FROM MSP_EpmProject_UserView LEFT JOIN MSP_EpmTask_UserView ON 
    MSP_EpmProject_UserView.ProjectUID = MSP_EpmTask_UserView.ProjectUID LEFT JOIN
    MSP_EpmAssignment_UserView ON MSP_EpmTask_UserView.TaskUID = 
    MSP_EpmAssignment_UserView.TaskUID LEFT JOIN MSP_EpmResource_UserView ON 
    MSP_EpmAssignment_UserView.ResourceUID = MSP_EpmResource_UserView.ResourceUID 
    WHERE (MSP_EpmTask_UserView.TaskIsProjectSummary = 0) GROUP BY 
    MSP_EpmProject_UserView.[Project nr]
4

1 に答える 1

0

UNPIVOT以下の例のようなものを使用する必要があります。

SELECT  [Project nr], Task, TaskDate
FROM    (
        SELECT   MSP_EpmProject_UserView.[Project nr]
                ,MAX(CASE   WHEN [Task Type Production] = 'Packed' 
                            THEN [Task deadline] 
                        END) AS Pack
                ,MAX(CASE   WHEN [Task Type Production] = 'Leave Production' 
                            THEN [Task deadline]
                        END) AS [Leave Production]
                ,MAX(CASE   WHEN [Task Type Production] = 'Flight Date' 
                            THEN [Task deadline]
                        END) AS [Flight Date]
        FROM    MSP_EpmProject_UserView 
                LEFT JOIN MSP_EpmTask_UserView 
                    ON MSP_EpmProject_UserView.ProjectUID = MSP_EpmTask_UserView.ProjectUID 
                LEFT JOIN MSP_EpmAssignment_UserView 
                    ON MSP_EpmTask_UserView.TaskUID = MSP_EpmAssignment_UserView.TaskUID 
                LEFT JOIN MSP_EpmResource_UserView 
                    ON MSP_EpmAssignment_UserView.ResourceUID = MSP_EpmResource_UserView.ResourceUID 
        WHERE (MSP_EpmTask_UserView.TaskIsProjectSummary = 0) 
        GROUP BY MSP_EpmProject_UserView.[Project nr]
        ) data
        UNPIVOT
        (
          TaskDate
          for [Task] in ([Pack],[Leave Production],[Flight Date])
        ) piv
ORDER BY    data.[Task deadline]
于 2013-02-19T11:32:16.260 に答える