我如何获取数据:
OrderID | Ver | Res | OI | Ret | Corp
-----------------------------------------------
1 | 'BUD' | 57823 | 11111 | 34304 | 12344
2 | 'ACT' | 12345 | 23456 | 45678 | NULL
要
Ver1 | Res1 | OI1 | Ret1 | Corp1 | Ver2 | Res2 | OI2 | Ret2 | Corp2
-----------------------------------------------------------------------------
'BUD' | 57823 | 11111 | 34304 | 12344 | 'ACT' | 12345 | 23456 | 45678 | NULL
我是否使用多个PIVOTS?!?!
答案 0 :(得分:2)
$output = $crud->render();
array_push($output->js_files, base_url("assets/my_js_folder/myjs.file.js"));
array_push($output->js_files, base_url("assets/another_js/config.module.js"));
$this->output($output);
答案 1 :(得分:0)
以下查询适用于任意数量的行。
DECLARE @SQL NVARCHAR(MAX)
WITH CTE
AS
(
SELECT 1 AS REF,Q,CONCAT(ITEM,ORDERID) AS COL FROM(
SELECT CAST(ORDERID AS VARCHAR(100)) AS ORDERID,
CAST(VER AS VARCHAR(100)) AS VER,
CAST(RES AS VARCHAR(100)) AS RES,
CAST(OI AS VARCHAR(100)) AS OI,
CAST(RET AS VARCHAR(100)) AS RET,
CAST(CORP AS VARCHAR(100)) AS CORP FROM ORDERS) K
UNPIVOT
(Q FOR ITEM IN (VER,RES,[OI],RET,CORP)) UP
)
SELECT @SQL = N'WITH CTE
AS
(
SELECT 1 AS REF,Q,CONCAT(ITEM,ORDERID) AS COL FROM(
SELECT CAST(ORDERID AS VARCHAR(100)) AS ORDERID,
CAST(VER AS VARCHAR(100)) AS VER,
CAST(RES AS VARCHAR(100)) AS RES,
CAST(OI AS VARCHAR(100)) AS OI,
CAST(RET AS VARCHAR(100)) AS RET,
CAST(CORP AS VARCHAR(100)) AS CORP FROM ORDERS) K
UNPIVOT
(Q FOR ITEM IN (VER,RES,[OI],RET,CORP)) UP
)
SELECT * FROM CTE
PIVOT
(MAX(Q) FOR COL IN ('+ STUFF((SELECT ','+COL FROM CTE FOR XML PATH('')),1,1,'') +')) P'
EXEC SP_EXECUTESQL @SQL