Select a.NID,a.Fee as Fee1,a.Curr,b.Fee as Fee2,b.Curr
from T1 a join T2 b on a.NID = b.NID AND a.Fee <>b.Fee

解决方案 »

  1.   

    1:测试环境
    create table t1(NID char(3),Fee int,Curr varchar(10))
    insert T1 select 
    'AAA', 100  ,'元'
    Union all select
    'BBB', 300  ,'美元'
    Union all select
    'CCC', 500  ,'港币'
    Union all select
    'DDD', 200  ,'元'  create table T2(NID char(3),Fee int,Curr varchar(10))
    insert T2 select
    'AAA', 300  ,'美元'
    Union all select
    'BBB', 100  ,'元'
    Union all select
    'BBB', 200  ,'美元'
    Union all select
    'CCC', 200  ,'港币'
    Union all select
    'DDD', 200  ,'元'2:查询
    Select a.NID,a.Fee as Fee1,a.Curr,b.Fee as Fee2,b.Curr
    from T1 a join T2 b on a.NID = b.NID AND a.Fee <>b.Fee3:结果
    NID  Fee1        Curr       Fee2        Curr       
    ---- ----------- ---------- ----------- ---------- 
    AAA  100         元          300         美元
    BBB  300         美元         100         元
    BBB  300         美元         200         美元
    CCC  500         港币         200         港币(所影响的行数为 4 行)
      

  2.   

    BBB  300         美元         100         元
    BBB  300         美元         200         美元
    这里.我只是想在下面以美元作一个小分组.结果应是
    BBB                           100         元
    BBB  300         美元         200         美元
      

  3.   

    Select a.NID,a.Fee as Fee1,a.Curr,b.Fee as Fee2,b.Curr
    from T1 a , T2 b where a.NID = b.NID AND a.Fee <>b.Fee
      

  4.   

    to: leimin
    结果还是同 txlicenhe的.不可以呀
      

  5.   

    我用
    select  t1.nid as A, T1.fee as B, T1.curr as C, T2.fee as D, T2.curr as E from  T1 left join  T2 on ( T2.nid= T1.nid and  T2.curr= T1.curr)
    union all
    select t2.nid as A, T1.fee as B, T1.curr as C, T2.fee as D, T2.curr as E from  T1 left join  T2 on ( T2.nid= T1.nid and  T2.curr= T1.curr)
    where T2.Nid is null但结果是
    AAA  100         元          NULL        NULL
    BBB  300         美元         200         美元
    CCC  500         港币         200         港币
    DDD  200         元          200         元
    NULL 100         元          NULL        NULL最后一行那应是
    BBB 100         元          NULL        NULL
      

  6.   

    select  t1.nid as A, T1.fee as B, T1.curr as C, T2.fee as D, T2.curr as E from  T1 left join  T2 on ( T2.nid= T1.nid and  T2.curr= T1.curr)
    union all
    select t1.nid as A, T1.fee as B, T1.curr as C, T2.fee as D, T2.curr as E from  T1 left join  T2 on ( T2.nid= T1.nid and  T2.curr= T1.curr)
    where T2.Nid is null你把后面那句改为select t1.nid就可以了
      

  7.   

    不可以的.其结果还是不是我想要的
    AAA  100         元          NULL        NULL
    BBB  300         美元         200         美元
    CCC  500         港币         200         港币
    DDD  200         元          200         元
    AAA  100         元          NULL        NULL
      

  8.   

    Select a.NID,a.Fee as Fee1,a.Curr,b.Fee as Fee2,b.Curr
    from T1 a , T2 b where a.NID = b.NID AND a.Fee <>b.Fee
      

  9.   

    我的意思是把以下结果
    AAA 0 NULL 300 美元
    AAA 500 港币 0 NULL
    AAA 100 美元 0 NULL
    AAA 100 元 0 NULL
    BBB 0 NULL 200 美元
    BBB 0 NULL 100 元
    BBB 300 美元 0 NULL
    CCC 0 NULL 200 港币
    CCC 500 港币 0 NULL
    DDD 0 NULL 200 元
    DDD 200 元 0 NULL
    EEE 0 NULL 10 元分组为:
    AAA 500 港币 0 NULL
    AAA 100 美元 300 美元
    AAA 100 元 0 NULL
    BBB 0 NULL 100 元
    BBB 300 美元 200 美元
    CCC 500 港币 200 港币
    DDD 200 元 200 元
    EEE 0 NULL 10 元
      

  10.   

    declare @你的表 table(分组 varchar(10),值1 int,货币1 varchar(10),值2 int,货币2 varchar(10))
    insert @你的表 values('AAA', 0 ,NULL, 300 ,'美元')
    insert @你的表 values('AAA', 500 ,'港币', 0 ,NULL)
    insert @你的表 values('AAA', 100 ,'美元', 0 ,NULL)
    insert @你的表 values('AAA', 100 ,'元', 0 ,NULL)
    insert @你的表 values('BBB', 0 ,NULL, 200 ,'美元')
    insert @你的表 values('BBB', 0 ,NULL, 100 ,'元')
    insert @你的表 values('BBB', 300 ,'美元', 0 ,NULL)
    insert @你的表 values('CCC', 0 ,NULL, 200 ,'港币')
    insert @你的表 values('CCC', 500 ,'港币', 0 ,NULL)
    insert @你的表 values('DDD', 0 ,NULL, 200 ,'元')
    insert @你的表 values('DDD', 200, '元', 0 ,NULL)
    insert @你的表 values('EEE', 0, NULL ,10 ,'元')
    select isnull(a.分组,b.分组) 分组,isnull(a.值1,0) 值1,a.货币1,isnull(b.值2,0) 值2,b.货币2 from (select * from @你的表 where 货币2 is null) a full join (select * from @你的表 where 货币1 is null) b on a.分组=b.分组 and a.货币1=b.货币2 order by isnull(a.分组,b.分组)
      

  11.   

    selsct t1.nid.t1.fee as feel,t1.curr,t2.fee as fee2,t2.curr
    from t1,t2
    where t1.nid=t2.nid and fee1<>fee2