select id,col1,'' as col2 from table where ....
union all
select id,'' as col1,col2 from table where ...

解决方案 »

  1.   

    select id,col1,'' col2 from 表 where 条件
    union all
    select id,'',col2 from 表 where 条件
      

  2.   

    select 剩下的抄上面两位的。
      

  3.   

    好啊,实际就是统计各项数据,现在大概有四十多个吧,是分开的;
    现在要弄到一个数据集里(四十多列),下面是现在用的的sql
    select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II 
    Where OBcbFlag='Rcv' 
    and OalId='A2'
    and Rspcode='12'
    and Datemsg like '200301%'
    and InExCode='Intra'
    and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
    and Left(BankCode,6) in ('080313','080402')
    Group by   BankCode  
    order by BankCode
    select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II 
    Where OBcbFlag='Rcv' 
    and OalId='A2'
    and Rspcode='14'
    and Datemsg like '200301%'
    and InExCode='Intra'
    and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
    and Left(BankCode,6) in ('080313','080402')
    Group by   BankCode  
    order by BankCode
    select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II 
    Where OBcbFlag='Rcv' 
    and OalId='A2'
    and Rspcode='30'
    and Datemsg like '200301%'
    and InExCode='Intra'
    and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
    and Left(BankCode,6) in ('080313','080402')
    Group by   BankCode  
    order by BankCode
      

  4.   

    select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II 
    Where OBcbFlag='Rcv' 
    and OalId='A2'
    and Rspcode='30'
    and Datemsg like '200301%'
    and InExCode='Intra'
    and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
    and Left(BankCode,6) in ('080313','080402')
    Group by   BankCode , Rspcode
    order by BankCode,Rspcode可以用
    select BankCode , sum(TxnNum) from BasicDataPerDayOnBank_II 
    Where OBcbFlag='Rcv' 
    and OalId='A2'
    and Rspcode='30'
    and Datemsg like '200301%'
    and InExCode='Intra'
    and TxnCode in ('PCA','PPT','ACP','APT','ATZ','ATC')
    and Left(BankCode,6) in ('080313','080402')
    AND Rspcode in (12,14,30)
    Group by   BankCode , Rspcode
    order by BankCode,Rspcode