ORDER_ID从选择中删除,然后选择列
name:
SET @query = 'SELECt ' + @cols + ' from ( SELECt ORDER_ID, DSC_NAME -- <--- you didn't select the name here FROM test ) x pivot ( MIN(ORDER_ID) for DSC_NAME in (' + @cols + ') ) p '
并使用
MAX(DSC_Name)代替
MIN(ORDER_ID)。像这样:
SQL小提琴演示SET @query = 'SELECt '+ @cols + ' from ( SELECt DSC_NAME, Name FROM test ) x pivot ( MAX(DSC_Name) for NAME in (' + @cols + ') ) p ';
这将为您提供:
| DWG_DOC | EQIP_1 | EQIP_2 | PART | PRCS |---------------------------------------------------------| 34-1500-XXX | C0403 | C4054 | 34-1500-013 | 88-0000 |
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)