如何将: 
 jgbm     zcbh             firstUserId      secondUserId        thirdUserId
650000 650000101000016    NULL           b              NULL
650000 650000101000016     a                 NULL              NULL
650000 650000101000016    NULL               NULL               c用sql 转化为:
650000 650000101000016     a                 b               c请教各位专家?

解决方案 »

  1.   

    SELECT jgbm,zcbh,firstUserId=MAX(firstUserId),secondUserId=MAX(secondUserId),thirdUserId=MAX(thirdUserId) 
    FROM TB GROUP BY jgbm,zcbh 
      

  2.   

    select coalesce(firstUserId,secondUserId,thirdUserId) from tb
      

  3.   

    select jgbm,zcbh,
    a=max([firstUserId]),
    b=max([secondUserId]),
    c=max([thirdUserId])
    from @T
    group by jgbm,zcbh
      

  4.   

    create table t(gbm varchar(30),zcbh varchar(30),firstUserId varchar,secondUserId varchar,thirdUserId  varchar)
    insert t
    select '650000', '650000101000016' ,   NULL, 'b'  ,        NULL  union  all
    select '650000', '650000101000016' ,   'a'   ,NULL  ,      NULL  union  all
    select '650000', '650000101000016',   NULL , NULL   ,       'c'  
    select gbm ,   zcbh ,max(firstUserId) firstUserId,max(secondUserId) secondUserId,max(thirdUserId ) thirdUserId
    from t
    group by gbm ,   zcbh
    drop table t
      

  5.   

    select 棒性,班次,开始,结束, profile = 有记录, profile = 有地标 from 巡更 
    union all
    select 棒性,班次,开始,结束, profile = 无记录, profile = 无地标 from 巡更
     order by 棒性,班次,开始,结束怎样将上面的结束保存入临时表里?因有两个字段都是“profile”