[200分]如何用一条SQL 语句删除表中重复的记录,但要保留一条,具体如下 :急等!!!!!!!!!(在线等待)

zsq666 2005-06-08 09:07:11
在emply表中有(id,name,sex)字段
 记录('001','张三','男')重复有10条
 记录('002','李死','')重复有8条
用一条SQL 语句删除表中重复的记录,但要保留一条!
...全文
202 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mengzulin 2005-06-09
  • 打赏
  • 举报
回复
begin tran
select DISTINCT [id],[name],[sex] into #temp from emply
TRUNCATE TABLE emply
INSERT INTO emply([id],[name],[sex])
select [id],[name],[sex] from #temp
commit tran
net_cavalier 2005-06-08
  • 打赏
  • 举报
回复
Oracle 中可用:
delete from emply a where rowid > (select min(rowid) from emply where id=a.id and name=a.name and sex =a.sex)

Sql server中用一条语句难办,估计这种要求只有答题时才有,上面可应付了
paoluo 2005-06-08
  • 打赏
  • 举报
回复
在emply表中有(id,name,sex)字段
 记录('001','张三','男')重复有10条
 记录('002','李死','')重复有8条
用一条SQL 语句删除表中重复的记录,但要保留一条!
------------------------------------------------
常用的方法:借用临时表
Select Distinct * Into #T from emply
Delete from emply
Insert emply Select * from #T
Drop table #T
xluzhong 2005-06-08
  • 打赏
  • 举报
回复
create table a(id nvarchar(10),name nvarchar(10),sex nvarchar(10))
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
go
alter table a add sid int identity(1,1)
go
delete a from a t where sid not in (select top 1 sid from a where id=t.id order by sid)
go
alter table a drop column sid
go

select * from a

drop table a
xluzhong 2005-06-08
  • 打赏
  • 举报
回复
create table a(id nvarchar(10),name nvarchar(10),sex nvarchar(10))
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''
insert into a select '001','张三','男'
insert into a select '002','李死',''

select distinct * into #t from a
truncate table a

insert into a select * from #t

select * from a

drop table a,#t
xluzhong 2005-06-08
  • 打赏
  • 举报
回复
alter table emplay sid int identity(1,1)
go
delete a
from emplay a where id not in (select top 1 sid form emplay where id=a.id order by sid)
go
alter table emplay dorp column sid
zsq666 2005-06-08
  • 打赏
  • 举报
回复
up
zsq666 2005-06-08
  • 打赏
  • 举报
回复
up
内容概要:本文介绍了基于粒子群优化(PSO)算法的光伏最大功率点跟踪(MPPT)控制模型,重点针对局部遮阴条件下光伏系统易出现多峰输出特性而导致传统MPPT方法失效的问题,提出采用PSO算法实现全局寻优的解决方案。该模型通过Simulink平台搭建光伏阵列、DC-DC变换器及PSO控制模块,模拟复杂光照条件下的系统运行状态,有效克服了局部遮阴引起的功率震荡和误判问题,提升了光伏发电系统的能量转换效率与稳定性。文详细阐述了PSO算法的实现流程及其与MPPT控制的结合方式,并通过仿真实验验证了该方法在动态环境下的快速响应能力和高精度追踪性能。; 适合人群:具备一定电力电子与自动控制理论基础,从事新能源发电、智能优化算法应用或光伏系统设计等相关领域的科研人员及工程技术人员,尤其适合研究生及以上学历层次的学习者。; 使用场景及目标:① 解决光伏系统在局部遮阴工况下的最大功率点追踪难题;② 学习并掌握智能优化算法(如PSO)在实际工程控制的建模与实现方法;③ 开展基于Simulink的光伏系统仿真研究,提升对MPPT控制策略的理解与创新能力; 阅读建议:建议结合提供的Simulink仿真模型文件进行实践操作,重点关注PSO算法参数设置、寻优过程可视化以及与其他传统MPPT方法(如扰动观察法、电导增量法)的对比析,以深入理解其优越性与适用边界。

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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