insert 另一个表 select * from rrd_info tem where createtime=(select max(createtime) from rrd_info where srcmobile=tem.srcmobile)

解决方案 »

  1.   

    你这里面没有重复记录select srcmobile,[password],max(createtime) as createtime into #temp from rrd_info group by srcmobile,[password]select * from #temp
      

  2.   

    select srcmobile,max(password),max(createtime) from 表 group by srcmobile
      

  3.   

    如果情况只是像你上面所说的,你可以crcmobile列为主,你的createtime列的值一定是定义为getdate()吧?这样createtime列的时间值不会重复;其实用如下方法就行了:select distinct(srcmobile),password,createtime
    into new_table
    from rrd_info
      

  4.   

    上面的逗号写错了!正确如下:select distinct(srcmobile),password,createtime
    into new_table
    from rrd_info
      

  5.   

    declare @tmp table (srcmobile bigint,password int,createtime datetime)
    insert into @tmp values(13501621251      ,   62372171 ,  '2003-08-18 20:42:29.000')
    insert into @tmp values(13501621251      ,   62372178 ,  '2003-09-15 18:36:57.000')select a.* from @tmp a,(select a.srcmobile,max(a.createtime) as createtime from @tmp a group by a.srcmobile) b where a.srcmobile=b.srcmobile and a.createtime=b.createtime
    要考濾password要取最後修改時間那個,而不是max
      

  6.   

    Select Distinct srcmobile,password,Max(createtime) 
    Into new_table 
    From rrd_info 
      

  7.   


    insert into newtable
    select srcmobile,[password],max(createtime) as createtime 
    from rrd_info 
    group by srcmobile,[password]