类似于这样的一个数据库表。现在想把13号的数据按相同id复制到20号中应该使用什么命令?

解决方案 »

  1.   

    try this,update a
     set a.STARTTIME=b.STARTTIME,
         a.ENDTIME=b.ENDTIME
     from [表名] a
     inner join (select * 
                 from [表名]
                 where [TIME]='2014-10-13') b on a.ID=b.ID
     where a.[TIME]='2014-10-20'
      

  2.   

     update a set starttime=b.starttime
     from tablename  a   join (select * from tablename  where time='2014-10-13') as b
     on a.id=b.id
     where a.time='2014-10-20'
      

  3.   

    update a 
    set a.STARTTIME=b.STARTTIME, a.ENDTIME=b.ENDTIME 
    from tablename a ,(select * from tablename where [TIME]='2014-10-13') b 
    where a.ID=b.ID and a.[TIME]='2014-10-20'
      

  4.   

    这个不行啊
    /* Error message: SQL script is wrong 
    mismatched input . expecting "EQ" */ 
      

  5.   

    这是你程序的问题,并不是sql 语句的问题。只不过你需要做的是将sql中的表名换成你数据库对应的表名。
      

  6.   

    你连接的数据是sql server吗?
      

  7.   

    SQLite 的库吗?
      

  8.   

    是的。sqlite开发的db文件
      

  9.   


    --通过游标实现即可。declare yb cursor for select id,starttime,endtime from 表名 where time='2014-10-13'
    open yb 
    fetch next from yb into @id2,@starttime2,@endtime2
    while @@FETCH_STATUS=0
       begin
           update 表名 set starttime=@starttime2,endtime=@endtime2 
            where id=@id2 and time='2014-10-20'
            fetch next from yb into @id2,@starttime2,@endtime2
       end
    close yb
    deallocate yb
      

  10.   

    这个问题如果表对应好了,方法 update a set starttime=b.starttime
     from tablename  a   join (select * from tablename  where time='2014-10-13') as b
     on a.id=b.id
     where a.time='2014-10-20' 是没有问题的啊,这样的问题用游标处理我还是第一次见到