1
ID     Type       Category      Description

20     Space      Board Type    Painted Bulletin Revenue
21     Space      Board Type    8-Sheet Billboard Revenue
22     Space      Board Type    Short Term Revenue

这是我拥有的表格,因为描述可能很大我想在下面的格式上进行选择,它用于填充网格并且可以在前端完成,但如果它在 sql 上很好

ID                             Type       Category   

20                             Space      Board Type    
Painted Bulletin Revenue
21                             Space      Board Type    
8-Sheet Billboard Revenue
22                             Space      Board Type    
Short Term Revenue
4

1 回答 1

3

试试这个

SELECT [ID], [Type], [Category] FROM
(
    SELECT 1 AS SNo,CONVERT(VARCHAR(1000),[ID]) AS ID , [Type], [Category],ROW_NUMBER() OVER(ORDER BY [ID]) rnk FROM Table1
    UNION ALL
    SELECT 2 AS SNo,[Description]  AS ID,'' AS [Type],'' AS [Category],ROW_NUMBER() OVER(ORDER BY [ID]) rnk FROM Table1
) t
ORDER BY rnk,SNo

SQL 小提琴演示

输出

ID                      Type    Category
20                      Space   Board Type
Painted Bulletin Revenue        
21                      Space   Board Type
8-Sheet Billboard Revenue       
22                      Space   Board Type
Short Term Revenue
于 2013-08-22T05:42:05.300 回答