格式输出行到列sql查询

时间:2013-11-15 00:54:36

标签: sql sql-server

我有基于[测试参数名称]的表(行)格式的以下数据。

[Serial Number] [Model]  [Recv_Date]      [Test Date]    [Test Parameter Name]  [Test Value]  [Test Result]  [Tester Name_ID]   [Error_Defect Code]
100811000023     M9001   3/20/13 14:18    3/22/13 0:42   Test_1                 0             FAIL           dev04_9            DC01
100811000023     M9001   3/20/13 14:18    3/22/13 0:42   Test_2                 100           PASS           dev04_9            DC01
100811000023     M9001   3/20/13 14:18    3/22/13 0:42   Test_3                 0             FAIL           dev04_9            DC02
100811000023     M9001   3/20/13 14:18    3/22/13 0:42   Test_4                 NULL          SKIPPED        dev04_9            DC02
100811000023     M9001   3/20/13 14:18    3/22/13 0:42   Test_5                 120           PASS           dev04_9            DC03
100899000345     M9001   3/20/13 23:28    3/21/13 15:55  Test_1                 99            PASS           dev09_5            DC01
100899000345     M9001   3/20/13 23:28    3/21/13 15:55  Test_2                 101           PASS           dev09_5            DC01
100899000345     M9001   3/20/13 23:28    3/21/13 15:55  Test_3                 103           PASS           dev09_5            DC02
100899000345     M9001   3/20/13 23:28    3/21/13 15:55  Test_4                 100           PASS           dev09_5            DC02
100899000345     M9001   3/20/13 23:28    3/21/13 15:55  Test_5                 119           PASS           dev09_5            DC03
100811000023     M9001   3/20/13 14:18    3/23/13 13:15  Test_1                 0             FAIL           dev04_9            DC01
100811000023     M9001   3/20/13 14:18    3/23/13 13:15  Test_2                 100           PASS           dev04_9            DC01
100811000023     M9001   3/20/13 14:18    3/23/13 13:15  Test_3                 0             FAIL           dev04_9            DC02
100811000023     M9001   3/20/13 14:18    3/23/13 13:15  Test_4                 NULL          SKIPPED        dev04_9            DC02
100811000023     M9001   3/20/13 14:18    3/23/13 13:15  Test_5                 120           PASS           dev04_9            DC03

我需要输出为[序列号]的单个记录,基于最大[测试日期](一个单元可以多次运行)。然后,我需要查看所有[测试参数名称]的测试结果,看看他们是否已通过或未通过。如果多次失败,我需要按优先级显示[Error_Defect Code]。注意:多个测试分组为[Error_Defect Code],在示例数据中,任何失败测试的报告优先级为:[Error_Defect Code] =“DC03”,然后是“DC02”,“DC01”....如果所有测试都通过,则显示[Error_Defect Code]的“DC00”。我还想调整[测试参数名称]以显示[测试值]。

数据示例仅显示5个不同的[测试参数名称]值。实际上,我的实际数据有100个不同的[测试参数名称]值和15个不同的[Error_Defect Code]。

听到我希望输出看起来如何:

[Serial Number] [Model]  [Recv_Date]    [Test Date]   [Test Result] [Error_Defect Code] [Tester Name_ID]  [Test_1] [Test_2] [Test_3] [Test_4] [Test_5]...
100811000023    M9001    3/20/13 14:18  3/23/13 13:15 FAIL          DC02                dev04_9            0       100      0        NULL     120
100899000345    M9001    3/20/13 23:28  3/21/13 15:55 PASS          DC00                dev09_5            99      101      103      100      119

0 个答案:

没有答案