我的查询是:
SELECT TOP 2 trans_date_np FROM day_in_status_mcg ORDER BY day_in_id DESC
结果:
2070÷10÷02 ->row 1
2070÷10÷01 ->row 2
我可以得到这样的结果:
column 1 column 2
2070÷10÷02 2070÷10÷02
我尝试使用XML PATH。 ' trans_date_np'是varchar。
答案 0 :(得分:2)
如果您知道有多少行,可以使用pivot语句。
SELECT [1], [2], [3], [4], [5]
FROM
(SELECT TOP 5 trans_data_np, ROW_NUMBER() over (order by day_in_id) as rowNumber
FROM day_in_status_mcg
ORDER BY day_in_id
) AS SourceTable
PIVOT
(
min(trans_data_np)
FOR rowNumber IN ([1], [2], [3], [4], [5])
) AS PivotTable;
答案 1 :(得分:0)
您可以使用以下查询: -
SELECT MAX(trans_date_np) AS column1, (SELECT MAX(trans_date_np)
FROM day_in_status_mcg
WHERE trans_date_np< SELECT MAX(trans_date_np)
FROM day_in_status_mcg) AS column2
FROM day_in_status_mcg;
我希望这能解决你的问题。