SQL简单问题,在线给分。

hzyzx 2002-04-22 10:46:53
我有一表TABLE1中 N列字段数据,我的主键是三个字段NUM,IDNO,NAME
现在列NUM的数据肯定有重复,问题是我现在需要把NUM列重复的数据出掉
又要列出所有字段,该怎么办?
...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wylyf 2002-04-22
  • 打赏
  • 举报
回复
select * from #tmp where num in(
select num from #tmp group by num having count(num)>1)
可以把所有NUM重复的列显示出来

想删除的话:
delete from #tmp where num in(
select num from #tmp group by num having count(num)>1)

x_zing 2002-04-22
  • 打赏
  • 举报
回复
--1,拿到你要的数据
select num,max(idno),max(name),...into table2 from table1
group by num
--2,在table2上加上主键(略)
--3,删除table1
drop table table1
--4,改table2为table1
sp_rename 'table2','table1'
Yang_ 2002-04-22
  • 打赏
  • 举报
回复
select * from tablename a
where idno=
(
select min(idno) as idno from tablename where num=a.num
)
and NAME=(
select min(NAME) as NAME from tablename where num=a.num and idno=a.idno
)

N_chow 2002-04-22
  • 打赏
  • 举报
回复
不知道是否是這樣?

SELECT NUM,MIN(IDNO) AS IDNO,MIN(NAME) as Name,MIN(...) as ...,MIN(...) as .......
From tableName
GROUP BY NUM

34,587

社区成员

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

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