你这里面没有重复记录select srcmobile,[password],max(createtime) as createtime into #temp from rrd_info group by srcmobile,[password]select * from #temp
select srcmobile,max(password),max(createtime) from 表 group by srcmobile
如果情况只是像你上面所说的,你可以crcmobile列为主,你的createtime列的值一定是定义为getdate()吧?这样createtime列的时间值不会重复;其实用如下方法就行了:select distinct(srcmobile),password,createtime into new_table from rrd_info
上面的逗号写错了!正确如下:select distinct(srcmobile),password,createtime into new_table from rrd_info
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
Select Distinct srcmobile,password,Max(createtime) Into new_table From rrd_info
insert into newtable select srcmobile,[password],max(createtime) as createtime from rrd_info group by srcmobile,[password]
into new_table
from rrd_info
into new_table
from rrd_info
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
Into new_table
From rrd_info
insert into newtable
select srcmobile,[password],max(createtime) as createtime
from rrd_info
group by srcmobile,[password]