sql 行转列

SELECT     sss
FROM         (SELECT     TOP (1) 1 AS Expr1, A AS sss
                       FROM          com_jjxx
                       UNION
                       SELECT     TOP (1) 2 AS Expr1,  B AS aaaa
                       FROM         com_jjxx AS com_jjxx_5
                       UNION
                       SELECT     TOP (1) 3 AS Expr1,  C AS bbb
                       FROM         com_jjxx AS com_jjxx_4
                       UNION
                       SELECT     TOP (1) 4 AS Expr1,  D AS ccc
                       FROM         com_jjxx AS com_jjxx_3
                       UNION
                       SELECT     TOP (1) 5 AS Expr1, E AS ddd
                       FROM         com_jjxx AS com_jjxx_2
                       UNION
                       SELECT     TOP (1) 6 AS Expr1, F  AS eeee
                       FROM         com_jjxx AS com_jjxx_1) AS a

有必要解释一下... 1,2,3,4,5,6, 就是就要显示的内容的一个排序..  A,B,C,D,E,F 就是要显示的内容.当然, com_jjxx 这个表里面要有这些字段.     com_jjxx  后面也可以加WHERE  条件...

相关推荐