序号 姓名 数学 语文 自然 体育
1 肖志强 86.0 62.0 62.0 38.0
2 薛济国 60.0 75.0 68.0 63.0
3 何 立 81.0 67.0 61.0 60.0
以上是excel中的数据,我现在已到入到了SQL SERVER中
我想实现的是将其格式转换为如下:姓名 课程 分数
肖志强 数学 86
肖志强 语文 62
肖志强 自然 62
肖志强 体育 38
薛济国 数学 60
薛济国.....
怎么转换?各位帮一下,很急
select when ... then... as xxx ????
1 肖志强 86.0 62.0 62.0 38.0
2 薛济国 60.0 75.0 68.0 63.0
3 何 立 81.0 67.0 61.0 60.0
以上是excel中的数据,我现在已到入到了SQL SERVER中
我想实现的是将其格式转换为如下:姓名 课程 分数
肖志强 数学 86
肖志强 语文 62
肖志强 自然 62
肖志强 体育 38
薛济国 数学 60
薛济国.....
怎么转换?各位帮一下,很急
select when ... then... as xxx ????
UNION
(select [姓名],[课程]='语文',[分数]=convert(numeric(20,0),[语文]) from TableName)
UNION
(select [姓名],[课程]='自然',[分数]=convert(numeric(20,0),[自然]) from TableName)
UNION
(select [姓名],[课程]='体育',[分数]=convert(numeric(20,0),[体育]) from TableName)
你也可以用
select cast(分数 as numeric(10,0)) from tablename