select roll1 into #a from decp
insert into #a select roll2 from decp
insert into #a select roll3 from decp
insert into #a select roll4 from decp
insert into #a select roll5 from decp
select rool1 roll from #a where roll1<>0 order by roll1
insert into #a select roll2 from decp
insert into #a select roll3 from decp
insert into #a select roll4 from decp
insert into #a select roll5 from decp
select rool1 roll from #a where roll1<>0 order by roll1
的回答挺有意思
select roll1 form table where roll1<>0 union select roll2 .....
(
select roll1 as 'roll' from tt where roll1<>0 union
select roll2 as 'roll' from tt where roll2<>0 union
select roll3 as 'roll' from tt where roll3<>0 union
select roll4 as 'roll' from tt where roll4<>0 union
select roll5 as 'roll' from tt where roll5<>0
) w order by roll
(
select roll1 as 'roll' from tt where roll1<>0 union
select roll2 as 'roll' from tt where roll2<>0 union
select roll3 as 'roll' from tt where roll3<>0 union
select roll4 as 'roll' from tt where roll4<>0 union
select roll5 as 'roll' from tt where roll5<>0
)
这里后面还可以加 where吗?
你是应该加个where roll <> 0
(
select roll1 as 'roll' from tt where roll1<>0 union
select roll2 as 'roll' from tt where roll2<>0 union
select roll3 as 'roll' from tt where roll3<>0 union
select roll4 as 'roll' from tt where roll4<>0 union
select roll5 as 'roll' from tt where roll5<>0
)
这里后面必须加一个别名