1

以下是我正在使用的已经存储在表格中的内容

ParentID   ComputerName ProductCode
--------   ------------    ------------
117   AZ18LTDJBN2R1 EEADMIN_1000
117   AZ18LTDJBN2R1 EEGO____1000
117   AZ18LTDJBN2R1 EEPC
117   AZ18LTDJBN2R1 EPOAGENT3000
117   AZ18LTDJBN2R1 HOSTIPS_8000
117   AZ18LTDJBN2R1 PCR_____1000
117   AZ18LTDJBN2R1 SITEADV_3500
117   AZ18LTDJBN2R1 SUPPCLNT1000
117   AZ18LTDJBN2R1 VIRUSCAN8800

如何将这 9 行合并为 1 行,并为每个记录/产品代码添加列?

ParentID   ComputerName EEADMIN        EEGO            EEPC    EPOAgent        etc.   
--------   ------------    ------------  -------------   ------   ----------     ------
 117      AZ18LTDJBN2R1 EEADMIN_1000  EEGO____1000    EEPC     EPOAGENT3000    etc. 

任何帮助将不胜感激。谢谢。

4

1 回答 1

0

这是一种方法:

select ParentId, ComputerName,
       max(case when ProductCode like 'EEADMIN%' then ProductCode end) as EEAdmin,
       max(case when ProductCode like 'EEGO%' then ProductCode end) as EEGO,
       max(case when ProductCode like 'EEPC%' then ProductCode end) as EEPC,
       . . .
from t
group by ParentId, ComputerName
于 2013-06-26T01:45:59.693 回答