我想针对一个表编写一个查询,该表为一个故障单的“pm_process_guid”提供唯一值,并在列方式中为“已分配组”,“已分配用户”和“时间”中的所有关联值提供。如何编写查询以获得如下所示的输出?
pm_process_guid Assign Serial Number Assigned Group Assigned User Time
2E2A9A43-9607-4FCB-B3A7-550440823B20 1 APAC Ram 3/23/2016 15:06
2E2A9A43-9607-4FCB-B3A7-550440823B20 2 AM Raj 3/23/2016 15:06
2E2A9A43-9607-4FCB-B3A7-550440823B20 3 APAC Sree 3/23/2016 15:06
我需要得到如下的输出,
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pm_process_guid TotalAssign Count 1st Group 1st User Time 2nd Group 2nd User Time 3rd Group 3rd User Time
2E2A9A43-9607-4FCB-B3A7-550440823B20 3 APAC Ram 3/23/2016 15:06 AM Raj 3/23/2016 15:06 APAC Sree 3/23/2016 15:06
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
答案 0 :(得分:0)
这是关于如何做的示例合成。
SELECT pm_process_guid,
count(*),
[1st User] = MAX(CASE WHEN AssignSerial = 1 THEN AssignUser END),
[2nd User] = MAX(CASE WHEN AssignSerial = 2 THEN AssignUser END),
. . .
FROM yourtable
GROUP BY pm_process_guid