现在我有一张表A。。里面记录着用户每一次登录的信息。比如ID、IP、time现在有另外一张表B。里面有ID和IP两个字段。现在ID已经导进去了。要把某个时间最新的IP导入的B表中。怎么想也想不出来。只要上来求高手解答。UPDATE B
   SET ip = a.IP
from A a,B b
 WHERE a.ID = b.ID获取正确的IP
SELECT top 1 IP
  FROM a
where [time] < '2011-10-1'
order by [time] desc

解决方案 »

  1.   

    UPDATE B
      SET ip = (select top 1 ip from A where A.id=B.id order by [time] desc)
    from B
      

  2.   

    UPDATE B
      SET ip = a.IP
    from (SELECT top 1 IP, ID
      FROM a
    where [time] < '2011-10-1'
    order by [time] desc
    ) a, B b
     WHERE a.ID = b.ID
      

  3.   

    UPDATE
     B
    SET
     ip = (select top 1 ip from A where id=B.id where [time] < '2011-10-1'
    order by [time] desc)
    from
      B
      

  4.   

    UPDATE B
      SET ip = isnull((SELECT top 1 IP
      FROM a
    where [time] < '2011-10-1'
    and id = b.id
    order by [time] desc),b.ip)from B b
      

  5.   

    update 
      b
    set
      id=a.ip
    from
      (select top 1 ip,id from a where [time]<'2011-10-01' order by [time] desc)a
    left join 
       b
    on
       a.id=b.id