问题1、有A、B两个表,都有一列“序列号”,想实现如下功能: 
首先判断A、B两个表的序列号是否相同,如相同将两表的两条信息输出到C表。 问题2、有A、B两个表,都有一列“资产编号”,想实现如下功能: 
逐个使用B表的资产编号遍历A表资产编号,如果没有相同的就将资产编号输出到C表。 谢谢了

解决方案 »

  1.   

    问题1、有A、B两个表,都有一列“序列号”,想实现如下功能:   
    首先判断A、B两个表的序列号是否相同,如相同将两表的两条信息输出到C表。 
      两表的两条信息输出到C表?
    什么意思?AB表结构相同?
    请给出数据实例.否则我只能猜你想要什么!select a.*,b.*
    from a inner jion b on a.id=b.id
      

  2.   

    问题2、有A、B两个表,都有一列“资产编号”,想实现如下功能:   
    逐个使用B表的资产编号遍历A表资产编号,如果没有相同的就将资产编号输出到C表。

    insert into c
    select b.*
    from b left jion a on a.id=b.id
    where a.id is null假设你的需求如下
    Table A
    ID
    ==
    1
    2
    4
    6Table B
    ID
    ==
    1
    2
    3
    5
    6
    7Table C
    ID
    --
    3
    5
    7
      

  3.   

    /*
    问题1、有A、B两个表,都有一列“序列号”,想实现如下功能:  
    首先判断A、B两个表的序列号是否相同,如相同将两表的两条信息输出到C表。
    */
    -->交集
    insert into C表 (?) select a.(?) from A表 a join B表 b on a.序列号 = b.序列号
    insert into C表 (?) select b.(?) from A表 a join B表 b on a.序列号 = b.序列号/*
    问题2、有A、B两个表,都有一列“资产编号”,想实现如下功能:
    逐个使用B表的资产编号遍历A表资产编号,如果没有相同的就将资产编号输出到C表。
    */
    -->差集
    insert into C表 (?) select b.(?) from A表 a right join B表 b on a.资产编号 = b.资产编号 where a.资产编号 is null
      

  4.   


    create table a(id int,code char(1))
    insert a select 1,'a' 
    insert a select 2,'b' --1
    insert a select 3,'c' --1
    insert a select 4,'d' --1
    insert a select 5, 'e' 
    gocreate table b(id int,code char(1))
    insert b select 6,'f'--2
    insert b select 2,'b' 
    insert b select 3,'c' 
    insert b select 4,'d'
    insert b select 9, 'w'--2
    insert b select 10,'x'--2
    insert b select 11,'y'--2
    gocreate table c(id int,code char(1))
    go--第一个问题
    insert into c select a.* from a inner join b on a.id=b.id
    go--第二个问题
    insert into c select * from b where code not in(select code from a)
    go--检验结果
    select * from cdrop table a
    drop table b
    drop table c
      

  5.   

    --第一次查询结果
    2 b
    3 c
    4 d
      

  6.   

    --第二次查询结果 
    6 f
    9 w
    10 x
    11 y
      

  7.   


    问题1
    insert into C select * from A  join B on a.序列号 = b.序列号问题2
    insert into C select * from b  where 资产编号 not in(select 资产编号 from a)