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

解决方案 »

  1.   

    victorycyz(中海) 
    的回答挺有意思
      

  2.   

    用union
    select roll1 form table where roll1<>0 union select roll2 .....
      

  3.   

    select roll from 
    (
    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
      

  4.   

    感谢各位的回复,按你们的方法问题已经解决了,还想问一下,select roll from 
    (
    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吗?
      

  5.   

    可以呀!
    你是应该加个where roll <> 0
      

  6.   

    看错了,你不需要加这个where,但是可以在这种语句后面加where条件!
      

  7.   

    select roll from 
    (
    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

    这里后面必须加一个别名