现在一个表icbccs;内容如下
user_name       user_region     user_product    user_channelN1         AdminG1    userG1     userC1    
N2                    userG2     userC2    
N3         AdminG3    userG2     userC3    
N4                               userC4    
N5         AdminG4    userG1     userC4    
N6                    userG3     userC3    
N7         AdminG1    userG3     userC3    如果USER_REGION有就写, 没有不写, USER_PRODUCT也是, USER_CHANNEL也是
输出结果如下:
"N1","AdminG1"
"N1","UserG1"
"N1","UserC1"
"N2","UserG2"
"N2","UserC2"
...
...
...且顺序如上,请高手帮下忙,谢谢

解决方案 »

  1.   

    不好意思,上面表格有点乱,不知道怎么样弄的
    N1 AdminG1  userG1  userC1    
    N2          userG2  userC2    
    N3 AdminG3  userG2  userC3    
    N4                  userC4    
    N5 AdminG4  userG1  userC4    
    N6          userG3  userC3    
    N7 AdminG1  userG3  userC3    
      

  2.   

    select *
    from 
    (select user_name,user_region  from icbccs;
    union all
    select user_name,user_product  from icbccs; 
    union all 
    select user_name,user_channel  from icbccs;
    )T
    where
    user_region<>''
      

  3.   

    select user_name,user_region as s from icbccs where isnull(user_region,'') <>''
    union all
    select user_name,user_product as s from icbccs where isnull(user_product,'') <>''
    union all
    select user_name,user_channel  as s from icbccs where isnull(user_channel ,'') <>''
      

  4.   

    select * from (select user_name,user_region as s from icbccs where isnull(user_region,'') <>''
    union all
    select user_name,user_product as s from icbccs where isnull(user_product,'') <>''
    union all
    select user_name,user_channel  as s from icbccs where isnull(user_channel ,'') <>'')
    TEMP group by user_name;
      

  5.   

    谢谢各们帮忙,由于分不是很多了,只能平均给一些,希望大家不要介意
    我采用了wzy_love_sly 的方法
    并在后面加上一个order by user_name就可以完全达到我要的效果了
    还有,大家写的都不错,谢谢啦