求:列变行?

bfdhh 2006-02-07 11:51:07
一行记录:
行:1 2 3 4 5 6 7 8 9 10 11 12
值:0 1 0 1 0 1 1 1 1 0 0 0

值为1的列作为返回值,组成一个只有一列的表

如下:
ID
2
4
6
7
8
9


...全文
108 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
samfeng_2003 2006-02-07
  • 打赏
  • 举报
回复
create table t
([1] int,[2] int,[3] int,[4] int,[5] int,[6] int,[7] int,
[8] int,[9] int,[10] int,[11] int,[12] int)

insert t
select 0,1,0,1,0,1,1,1,1,0,0,0

create table t1
(id int)


insert t1
select col from
(
select [1] as id,1 as col from t
union all
select [2],2 from t
union all
select [3],3 from t
union all
select [4],4 from t
union all
select [5],5 from t
union all
select [6],6 from t
union all
select [7],7 from t
union all
select [8],8 from t
union all
select [9],9 from t
union all
select [10],10 from t
union all
select [11],11 from t
union all
select [12],12 from t
) a where id=1

select * from t1

drop table t,t1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧