dindan过滤完全重复和不完全重复记录 - 不含2014.sql 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. --0.备份当前db的dindan表到dindan_back中;
  2. select * into [db].[dbo].[dindan_back] from [db].[dbo].[dindan]
  3. go
  4. --1.将db的dindan表全部记录插入到#tempall表中;
  5. select * into #tempall from [db].[dbo].[dindan]
  6. go
  7. --2.过滤掉#tempall中完全重复的记录到#tempdis中;
  8. select distinct * into #tempdis from #tempall
  9. go
  10. drop table #tempall
  11. go
  12. --3.获取指定字段的不重复记录,过滤掉不完全重复的记录;
  13. select identity(int,1,1) as autoid, * into #temp1 from #tempdis
  14. select min(autoid) as autoid into #temp2 from #temp1 group by [id]
  15. select [id]
  16. ,[money1]
  17. ,[money2]
  18. ,[money3]
  19. ,[name1]
  20. ,[name2]
  21. ,[taoxiid]
  22. ,[taoxiname]
  23. ,[taoxijiage]
  24. ,[taoxizs]
  25. ,[time1]
  26. ,[time2]
  27. ,[time3]
  28. ,[bm]
  29. ,[ren]
  30. ,[discount]
  31. ,[payed1]
  32. ,[payed2]
  33. ,[payed3]
  34. ,[payed4]
  35. ,[payed5]
  36. ,[time4]
  37. ,[time5]
  38. ,[takezs]
  39. ,[choosezs]
  40. ,[status]
  41. ,[clothescount2]
  42. ,[outside2]
  43. ,[style]
  44. ,[payed3time]
  45. ,[payed4ren]
  46. ,[payed4time]
  47. ,[status2]
  48. ,[status3]
  49. ,[waiter1]
  50. ,[waiter2]
  51. ,[waiter3]
  52. ,[waiter4]
  53. ,[bz]
  54. ,[taketime]
  55. ,[clothescount]
  56. ,[outside]
  57. ,[bz2]
  58. ,[bz3]
  59. ,[urgent]
  60. ,[status4]
  61. ,[status5]
  62. ,[waiter5]
  63. ,[waiter6]
  64. ,[pinyin1]
  65. ,[pinyin2]
  66. ,[waiter7]
  67. ,[status6]
  68. ,[phone1]
  69. ,[phone2]
  70. ,[status7]
  71. ,[memberno]
  72. ,[waiter8]
  73. ,[time6]
  74. ,[status8]
  75. ,[bruncount]
  76. ,[tichenren1]
  77. ,[tichenren2]
  78. ,[tichenren3]
  79. ,[tichenren4]
  80. ,[tichenren5]
  81. ,[send1]
  82. ,[send2]
  83. ,[send3]
  84. ,[datetime4]
  85. ,[datetime5]
  86. ,[datetime6]
  87. ,[waiter12]
  88. ,[waiter13]
  89. ,[waiter14]
  90. ,[waiter22]
  91. ,[waiter23]
  92. ,[waiter24]
  93. ,[waiter1rate]
  94. ,[waiter12rate]
  95. ,[waiter13rate]
  96. ,[waiter14rate]
  97. ,[waiter2rate]
  98. ,[waiter22rate]
  99. ,[waiter23rate]
  100. ,[waiter24rate]
  101. ,[ren2]
  102. ,[renrate]
  103. ,[ren2rate]
  104. ,[delphotos]
  105. ,[delphotos2]
  106. ,[txtype]
  107. ,[growthtxselname]
  108. ,[designno]
  109. ,[designreplaceno]
  110. ,[size]
  111. ,[dindantype]
  112. ,[contractno1]
  113. ,[contractno2]
  114. ,[cfno]
  115. ,[calldate]
  116. ,[from]
  117. ,[reason]
  118. ,[time7]
  119. ,[time8]
  120. ,[time9]
  121. ,[time10]
  122. ,[authorize]
  123. ,[discount2]
  124. ,[authorize2]
  125. ,[bz4]
  126. ,[satisfaction1]
  127. ,[satisfaction2]
  128. ,[satisfaction3]
  129. ,[satisfaction4]
  130. ,[satisfaction5]
  131. ,[satisfaction6]
  132. ,[satisfaction7]
  133. ,[bz5]
  134. ,[send4]
  135. ,[send5]
  136. ,[waiter9]
  137. ,[curno]
  138. ,[xplrr]
  139. ,[xplrtime]
  140. ,[satisfaction8]
  141. ,[VisitPeople1]
  142. ,[VisitPeople2]
  143. ,[VisitPeople3]
  144. ,[VisitPeople4]
  145. ,[VisitPeople5]
  146. ,[VisitPeople6]
  147. ,[VisitPeople7]
  148. ,[VisitPeople8]
  149. ,[VisitTime1]
  150. ,[VisitTime2]
  151. ,[VisitTime3]
  152. ,[VisitTime4]
  153. ,[VisitTime5]
  154. ,[VisitTime6]
  155. ,[VisitTime7]
  156. ,[VisitTime8]
  157. into [db].[dbo].[dindan#] from #temp1 where autoid in(select autoid from #temp2) order by id
  158. go
  159. --4.将过滤好的记录重新插入原表;
  160. drop table [db].[dbo].[dindan]
  161. select * into [db].[dbo].[dindan] from [db].[dbo].[dindan#]
  162. go
  163. drop table #tempdis
  164. drop table #temp1
  165. drop table #temp2
  166. drop table [db].[dbo].[dindan#]
  167. --5.结束;