如何根据SQL中类似的列值拆分列

时间:2014-07-09 13:40:39

标签: sql

我有一个表格,其中包含3列studentidqualificationboard。 它显示像

Studentid   -   qualification   -      board
   1        -    highschool     -      cbse
   1        -    intermidiate   -      cbse 
   2        -    highschool     -     up board
   2        -    intermidiate   -     up board

我需要一个提供结果的查询,如。

 studentid  -    qualification-1  -   qualification-2  -   board-1  -   board-2
     1      -     highschool      -    intermidiate    -     cbse    -      cbse
     2      -     highschool      -    intermidiate    -    up board  -    up board

任何人都可以解决它吗?

1 个答案:

答案 0 :(得分:0)

SELECT studentid, qualification AS 'qualification-1', qualification AS 'qualification-2', board AS 'board-1', board AS 'board-2' WHERE 1 GROUP BY studentid

使用 AS 创建字段别名