上面这个是数据库的两张表,下面这个是要操作的
最右边的表中的数据也要从数据库中读取出来的,就是从第二个数据表中读取出来的,
要把最右边表中选择的数据移动到中间的表,然后在左边表中不能有移动到中间表中的数据,求SQL语句,

解决方案 »

  1.   

    你这是求SQL语句啊?貌似SQL语句实现不了你的功能。这个是编写程序的事情。
      

  2.   

    程序已经搞定了,就是SQL语句写不下去了
      

  3.   

    --单个业务员插入
    insert into 已选业务员 select * from 待选业务员 where 业务员编号 = '...'--所有业务员插入
    delete from 已选业务员
    insert into 已选业务员 select * from 待选业务员 --单个业务员删除
    delete from 已选业务员 where 业务员编号 = '...'--所有业务员删除
    delete from 已选业务员
      

  4.   

    第一个表是已选业务员表吗?
    怎么与第二个表关联?
    你的意思。右边已选业务 移动某到已选业务 ,然后左边的业务表,减去此业务员吗?
    保持总数一样。
    可使用事务,或者触发器
    大致意思是
    CREATE TRIGGER trigger业务 on 已选业务表
    for update,insert,delete
    as
      if exists(select 1 from inserted)
       begin
       delete from 业务员,inserted where 业务员.业务员编号 =inserted.业务员编号
      end
      else
      begin
      insert into 业务员 select * from deleted 
     end
      

  5.   

    --是这样么? 
    insert into 已选业务员 select * from 待选业务员
    --左边 表不能有右边表的数据
    select * from 用户列表 where checksum(*) not in(select checksum(*) from 等选业务员
    --如果需要判断的话 需要用触发器