请教一条SQL语句

pp_key 2003-08-23 01:52:04
有五个字段,前三个字段可能会重复,最后两个字段不重复,我想用语句实现,找出表中前三个字段不重复的所有信息,包括最后两个字段信息,

a,b,c,d,e
1,2,3,4,5
1,2,3,4,5
1,2,4,4,5

我想要的是
a,b,c,d,e
1,2,3,4,5
1,2,4,4,5
...全文
26 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2003-08-23
  • 打赏
  • 举报
回复
用临时表来处理:


--将不重复的数据导入到临时表
select distinct * into #temp from 表

--删除原表数据
truncate table 表

--从临时表中导回数据
insert into 表 select * from #temp

--处理完成后删除临时表
drop table #temp
pengdali 2003-08-23
  • 打赏
  • 举报
回复
就你题目上举的例:
select distinct * from 表

就你的题意:

select identity(int,1,1) ID,* into #temp from 表

select a,b,c,d,e from #temp aa where ID=(select min(ID) as ID from #temp where a = aa.a and b = aa.b and c=aa.c)

drop table #temp
txlicenhe 2003-08-23
  • 打赏
  • 举报
回复
select identity(int,1,1) as ID,* into #temp

select a,b,c,d,e from #temp aa
where ID in
(select min(ID) as ID from #temp bb
where aa.a = bb.a and aa.b = bb.b and aa.c = bb.c)

drop table #temp
yoki 2003-08-23
  • 打赏
  • 举报
回复
select identity(int,1,1) as NID,* into #temp
select a,b,c,d,e from #temp
where NID in(select min(NID) as NID from #temp group by a,b,c)
drop table #temp

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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