dindan过滤完全重复和不完全重复记录.sql 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. --0.备份当前db的dindan表到dindan_back中;
  2. select * into [db].[dbo].[dindan_back] from [db].[dbo].[dindan]
  3. go
  4. --1.将2014和db的dindan表全部记录插入到#tempall表中;
  5. select * into #tempall from [db].[dbo].[dindan]
  6. go
  7. insert #tempall
  8. ([id]
  9. ,[money1]
  10. ,[money2]
  11. ,[money3]
  12. ,[name1]
  13. ,[name2]
  14. ,[taoxiid]
  15. ,[taoxiname]
  16. ,[taoxijiage]
  17. ,[taoxizs]
  18. ,[time1]
  19. ,[time2]
  20. ,[time3]
  21. ,[bm]
  22. ,[ren]
  23. ,[discount]
  24. ,[payed1]
  25. ,[payed2]
  26. ,[payed3]
  27. ,[payed4]
  28. ,[payed5]
  29. ,[time4]
  30. ,[time5]
  31. ,[takezs]
  32. ,[choosezs]
  33. ,[status]
  34. ,[clothescount2]
  35. ,[outside2]
  36. ,[style]
  37. ,[payed3time]
  38. ,[payed4ren]
  39. ,[payed4time]
  40. ,[status2]
  41. ,[status3]
  42. ,[waiter1]
  43. ,[waiter2]
  44. ,[waiter3]
  45. ,[waiter4]
  46. ,[bz]
  47. ,[taketime]
  48. ,[clothescount]
  49. ,[outside]
  50. ,[bz2]
  51. ,[bz3]
  52. ,[urgent]
  53. ,[status4]
  54. ,[status5]
  55. ,[waiter5]
  56. ,[waiter6]
  57. ,[pinyin1]
  58. ,[pinyin2]
  59. ,[waiter7]
  60. ,[status6]
  61. ,[phone1]
  62. ,[phone2]
  63. ,[status7]
  64. ,[memberno]
  65. ,[waiter8]
  66. ,[time6]
  67. ,[status8]
  68. ,[bruncount]
  69. ,[tichenren1]
  70. ,[tichenren2]
  71. ,[tichenren3]
  72. ,[tichenren4]
  73. ,[tichenren5]
  74. ,[send1]
  75. ,[send2]
  76. ,[send3]
  77. ,[datetime4]
  78. ,[datetime5]
  79. ,[datetime6]
  80. ,[waiter12]
  81. ,[waiter13]
  82. ,[waiter14]
  83. ,[waiter22]
  84. ,[waiter23]
  85. ,[waiter24]
  86. ,[waiter1rate]
  87. ,[waiter12rate]
  88. ,[waiter13rate]
  89. ,[waiter14rate]
  90. ,[waiter2rate]
  91. ,[waiter22rate]
  92. ,[waiter23rate]
  93. ,[waiter24rate]
  94. ,[ren2]
  95. ,[renrate]
  96. ,[ren2rate]
  97. ,[delphotos]
  98. ,[delphotos2]
  99. ,[txtype]
  100. ,[growthtxselname]
  101. ,[designno]
  102. ,[designreplaceno]
  103. ,[size]
  104. ,[dindantype]
  105. ,[contractno1]
  106. ,[contractno2]
  107. ,[cfno]
  108. ,[calldate]
  109. ,[from]
  110. ,[reason]
  111. ,[time7]
  112. ,[time8]
  113. ,[time9]
  114. ,[time10]
  115. ,[authorize]
  116. ,[discount2]
  117. ,[authorize2]
  118. ,[bz4]
  119. ,[satisfaction1]
  120. ,[satisfaction2]
  121. ,[satisfaction3]
  122. ,[satisfaction4]
  123. ,[satisfaction5]
  124. ,[satisfaction6]
  125. ,[satisfaction7]
  126. ,[bz5]
  127. ,[send4]
  128. ,[send5]
  129. ,[waiter9]
  130. ,[curno]
  131. ,[xplrr]
  132. ,[xplrtime]
  133. ,[satisfaction8]
  134. ,[VisitPeople1]
  135. ,[VisitPeople2]
  136. ,[VisitPeople3]
  137. ,[VisitPeople4]
  138. ,[VisitPeople5]
  139. ,[VisitPeople6]
  140. ,[VisitPeople7]
  141. ,[VisitPeople8]
  142. ,[VisitTime1]
  143. ,[VisitTime2]
  144. ,[VisitTime3]
  145. ,[VisitTime4]
  146. ,[VisitTime5]
  147. ,[VisitTime6]
  148. ,[VisitTime7]
  149. ,[VisitTime8])
  150. select [id]
  151. ,[money1]
  152. ,[money2]
  153. ,[money3]
  154. ,[name1]
  155. ,[name2]
  156. ,[taoxiid]
  157. ,[taoxiname]
  158. ,[taoxijiage]
  159. ,[taoxizs]
  160. ,[time1]
  161. ,[time2]
  162. ,[time3]
  163. ,[bm]
  164. ,[ren]
  165. ,[discount]
  166. ,[payed1]
  167. ,[payed2]
  168. ,[payed3]
  169. ,[payed4]
  170. ,[payed5]
  171. ,[time4]
  172. ,[time5]
  173. ,[takezs]
  174. ,[choosezs]
  175. ,[status]
  176. ,[clothescount2]
  177. ,[outside2]
  178. ,[style]
  179. ,[payed3time]
  180. ,[payed4ren]
  181. ,[payed4time]
  182. ,[status2]
  183. ,[status3]
  184. ,[waiter1]
  185. ,[waiter2]
  186. ,[waiter3]
  187. ,[waiter4]
  188. ,[bz]
  189. ,[taketime]
  190. ,[clothescount]
  191. ,[outside]
  192. ,[bz2]
  193. ,[bz3]
  194. ,[urgent]
  195. ,[status4]
  196. ,[status5]
  197. ,[waiter5]
  198. ,[waiter6]
  199. ,[pinyin1]
  200. ,[pinyin2]
  201. ,[waiter7]
  202. ,[status6]
  203. ,[phone1]
  204. ,[phone2]
  205. ,[status7]
  206. ,[memberno]
  207. ,[waiter8]
  208. ,[time6]
  209. ,[status8]
  210. ,[bruncount]
  211. ,[tichenren1]
  212. ,[tichenren2]
  213. ,[tichenren3]
  214. ,[tichenren4]
  215. ,[tichenren5]
  216. ,[send1]
  217. ,[send2]
  218. ,[send3]
  219. ,[datetime4]
  220. ,[datetime5]
  221. ,[datetime6]
  222. ,[waiter12]
  223. ,[waiter13]
  224. ,[waiter14]
  225. ,[waiter22]
  226. ,[waiter23]
  227. ,[waiter24]
  228. ,[waiter1rate]
  229. ,[waiter12rate]
  230. ,[waiter13rate]
  231. ,[waiter14rate]
  232. ,[waiter2rate]
  233. ,[waiter22rate]
  234. ,[waiter23rate]
  235. ,[waiter24rate]
  236. ,[ren2]
  237. ,[renrate]
  238. ,[ren2rate]
  239. ,[delphotos]
  240. ,[delphotos2]
  241. ,[txtype]
  242. ,[growthtxselname]
  243. ,[designno]
  244. ,[designreplaceno]
  245. ,[size]
  246. ,[dindantype]
  247. ,[contractno1]
  248. ,[contractno2]
  249. ,[cfno]
  250. ,[calldate]
  251. ,[from]
  252. ,[reason]
  253. ,[time7]
  254. ,[time8]
  255. ,[time9]
  256. ,[time10]
  257. ,[authorize]
  258. ,[discount2]
  259. ,[authorize2]
  260. ,[bz4]
  261. ,[satisfaction1]
  262. ,[satisfaction2]
  263. ,[satisfaction3]
  264. ,[satisfaction4]
  265. ,[satisfaction5]
  266. ,[satisfaction6]
  267. ,[satisfaction7]
  268. ,[bz5]
  269. ,[send4]
  270. ,[send5]
  271. ,[waiter9]
  272. ,[curno]
  273. ,[xplrr]
  274. ,[xplrtime]
  275. ,[satisfaction8]
  276. ,[VisitPeople1]
  277. ,[VisitPeople2]
  278. ,[VisitPeople3]
  279. ,[VisitPeople4]
  280. ,[VisitPeople5]
  281. ,[VisitPeople6]
  282. ,[VisitPeople7]
  283. ,[VisitPeople8]
  284. ,[VisitTime1]
  285. ,[VisitTime2]
  286. ,[VisitTime3]
  287. ,[VisitTime4]
  288. ,[VisitTime5]
  289. ,[VisitTime6]
  290. ,[VisitTime7]
  291. ,[VisitTime8]
  292. from [2014].[dbo].[dindan]
  293. go
  294. --2.过滤掉#tempall中完全重复的记录到#tempdis中;
  295. select distinct * into #tempdis from #tempall
  296. go
  297. drop table #tempall
  298. go
  299. --3.获取指定字段的不重复记录,过滤掉不完全重复的记录;
  300. select identity(int,1,1) as autoid, * into #temp1 from #tempdis
  301. select min(autoid) as autoid into #temp2 from #temp1 group by [id]
  302. select [id]
  303. ,[money1]
  304. ,[money2]
  305. ,[money3]
  306. ,[name1]
  307. ,[name2]
  308. ,[taoxiid]
  309. ,[taoxiname]
  310. ,[taoxijiage]
  311. ,[taoxizs]
  312. ,[time1]
  313. ,[time2]
  314. ,[time3]
  315. ,[bm]
  316. ,[ren]
  317. ,[discount]
  318. ,[payed1]
  319. ,[payed2]
  320. ,[payed3]
  321. ,[payed4]
  322. ,[payed5]
  323. ,[time4]
  324. ,[time5]
  325. ,[takezs]
  326. ,[choosezs]
  327. ,[status]
  328. ,[clothescount2]
  329. ,[outside2]
  330. ,[style]
  331. ,[payed3time]
  332. ,[payed4ren]
  333. ,[payed4time]
  334. ,[status2]
  335. ,[status3]
  336. ,[waiter1]
  337. ,[waiter2]
  338. ,[waiter3]
  339. ,[waiter4]
  340. ,[bz]
  341. ,[taketime]
  342. ,[clothescount]
  343. ,[outside]
  344. ,[bz2]
  345. ,[bz3]
  346. ,[urgent]
  347. ,[status4]
  348. ,[status5]
  349. ,[waiter5]
  350. ,[waiter6]
  351. ,[pinyin1]
  352. ,[pinyin2]
  353. ,[waiter7]
  354. ,[status6]
  355. ,[phone1]
  356. ,[phone2]
  357. ,[status7]
  358. ,[memberno]
  359. ,[waiter8]
  360. ,[time6]
  361. ,[status8]
  362. ,[bruncount]
  363. ,[tichenren1]
  364. ,[tichenren2]
  365. ,[tichenren3]
  366. ,[tichenren4]
  367. ,[tichenren5]
  368. ,[send1]
  369. ,[send2]
  370. ,[send3]
  371. ,[datetime4]
  372. ,[datetime5]
  373. ,[datetime6]
  374. ,[waiter12]
  375. ,[waiter13]
  376. ,[waiter14]
  377. ,[waiter22]
  378. ,[waiter23]
  379. ,[waiter24]
  380. ,[waiter1rate]
  381. ,[waiter12rate]
  382. ,[waiter13rate]
  383. ,[waiter14rate]
  384. ,[waiter2rate]
  385. ,[waiter22rate]
  386. ,[waiter23rate]
  387. ,[waiter24rate]
  388. ,[ren2]
  389. ,[renrate]
  390. ,[ren2rate]
  391. ,[delphotos]
  392. ,[delphotos2]
  393. ,[txtype]
  394. ,[growthtxselname]
  395. ,[designno]
  396. ,[designreplaceno]
  397. ,[size]
  398. ,[dindantype]
  399. ,[contractno1]
  400. ,[contractno2]
  401. ,[cfno]
  402. ,[calldate]
  403. ,[from]
  404. ,[reason]
  405. ,[time7]
  406. ,[time8]
  407. ,[time9]
  408. ,[time10]
  409. ,[authorize]
  410. ,[discount2]
  411. ,[authorize2]
  412. ,[bz4]
  413. ,[satisfaction1]
  414. ,[satisfaction2]
  415. ,[satisfaction3]
  416. ,[satisfaction4]
  417. ,[satisfaction5]
  418. ,[satisfaction6]
  419. ,[satisfaction7]
  420. ,[bz5]
  421. ,[send4]
  422. ,[send5]
  423. ,[waiter9]
  424. ,[curno]
  425. ,[xplrr]
  426. ,[xplrtime]
  427. ,[satisfaction8]
  428. ,[VisitPeople1]
  429. ,[VisitPeople2]
  430. ,[VisitPeople3]
  431. ,[VisitPeople4]
  432. ,[VisitPeople5]
  433. ,[VisitPeople6]
  434. ,[VisitPeople7]
  435. ,[VisitPeople8]
  436. ,[VisitTime1]
  437. ,[VisitTime2]
  438. ,[VisitTime3]
  439. ,[VisitTime4]
  440. ,[VisitTime5]
  441. ,[VisitTime6]
  442. ,[VisitTime7]
  443. ,[VisitTime8]
  444. into [db].[dbo].[dindan#] from #temp1 where autoid in(select autoid from #temp2) order by id
  445. go
  446. --4.将过滤好的记录重新插入原表;
  447. drop table [db].[dbo].[dindan]
  448. select * into [db].[dbo].[dindan] from [db].[dbo].[dindan#]
  449. go
  450. drop table #tempdis
  451. drop table #temp1
  452. drop table #temp2
  453. drop table [db].[dbo].[dindan#]
  454. go
  455. --5.结束;