declare @i int, @phone varchar(50)
create table #tempTable
(
AutoId int null,
SendPhone varchar(50) null,
SendName varchar(50) null,
RecPhone varchar(50) null,
RecName varchar(50) null,
RecMsg varchar(300) null,
AddTime datetime null
)
insert into #tempTable (AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime) SELECT AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime FROM wld.HD_UserMsg WHERE SendPhone IN (SELECT SendPhone FROM wld.HD_UserMsg GROUP BY SendPhone HAVING (COUNT(SendPhone) > 1))
delete from #tempTable where #tempTable.AutoId != (select min(AutoId) from #tempTable as a where #tempTable.SendPhone = a.SendPhone)
insert into #tempTable (AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime) SELECT AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime FROM wld.HD_UserMsg WHERE SendPhone IN (SELECT SendPhone FROM wld.HD_UserMsg GROUP BY SendPhone HAVING (COUNT(SendPhone) = 1))
浙公网安备 33010602011771号