求一条SQL

tcxx2008 2010-03-24 09:29:50
如题:
在A表中
col1 col2 col3 col4 col5 col6 col7 col8 col9 列
1 a c d e f g h j
2 b r u u i o p p
3 q w d f e t t y
4 w y u i o y u p
5 l k j h g b m n

这样一个表,将整个表的col2 col3 col4 col5 col6 col7 col8 col9 导入到B表,B表中col2 col3 col4 col5 字段为唯一索引,不能重复

问题,怎么将A表中col2 col3 col4 col5 重复的去掉,只留住一条,导入时不出错
...全文
172 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcxx2008 2010-03-24
  • 打赏
  • 举报
回复
哎,试了几个方法都不行呢。

说的更明确些,
col1 col2 col3 col4 col5 col6 col7 col8 col9 列
9个列,导到B表的时候要确保col4 手机号码这一列唯一的,不能有重复
caixia615 2010-03-24
  • 打赏
  • 举报
回复
根据这几个唯一字段直接取其余字段最大或者最小就行了
东那个升 2010-03-24
  • 打赏
  • 举报
回复
LZ说的有问题,如果col2 col3 col4 col5相同,后面的列不同要怎么导入,取那条??????
中国风 2010-03-24
  • 打赏
  • 举报
回复
insert B
SELECT * --指定列
FROM A AS t1 WHERE ID =(SELECT TOP 1 ID FROM A WHERE col1 =t1.col1 AND col2=t1.col2 AND col3=t1.col3 AND col4=t1.col4 )
黄_瓜 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tcxx2008 的回复:]
请清楚点呢
delete
t
from
a t??
[/Quote]
试试三楼的
--小F-- 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tcxx2008 的回复:]
请清楚点呢
delete
t
from
a t??
[/Quote]
取个别名而已 别激动
tcxx2008 2010-03-24
  • 打赏
  • 举报
回复
请清楚点呢
delete
t
from
a t??
黄_瓜 2010-03-24
  • 打赏
  • 举报
回复
 insert into b
select col2 col3 col4 col5 col6 col7 col8 col9 from ta a
where not exists ( select 1 from ta where col2=a.col2 and id>a.id)
and not exists ( select 1 from ta where col2=a.col2 and id>a.id)
and not exists ( select 1 from ta where col3=a.col3 and id>a.id)
and not exists ( select 1 from ta where col4=a.col4 and id>a.id)
and not exists ( select 1 from ta where col5=a.col5 and id>a.id)
--小F-- 2010-03-24
  • 打赏
  • 举报
回复
delete
t
from
a t
where
exists(select 1 from a where col2=t.clo2 and col3=t.col3 and col4=t.col4 and col5=t.col5 and col1<>t.col1)
永生天地 2010-03-24
  • 打赏
  • 举报
回复
select distinct

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧