易截截图软件、单文件、免安装、纯绿色、仅160KB

删除重复数据的sql方法

表中有一些记录内容重复,也就是说这些记录除了ID不同之外,其他的信息都相同。需要把重复的记录保留一条,剩下的删除
--第一种方法
delete from temp where id not IN (select min(id) from temp group by col1,col2)
--对col1,col2,即要删除的数据col1,col2两个列都相同,删除id大的行
--第二种方法
with a as
(select row_number() over (partition by col1,col2 order by col1,col2) as rid,* from temp
)
delete a where rid>1
--partition by col1,col2 作用如group by col1,col2,即要删除的行col1,col2两个列的数据相同,删除id大的行


相关文档:

PL/SQL Best Practice On BULK COLLECT

On BULK COLLECT
By Steven Feuerstein Oracle ACE
Best practices for knowing your LIMIT and kicking %NOTFOUND
I have started using BULK COLLECT whenever I need to fetch large volumes of data. This has caused me some trouble with my DBA, however. He is complaining that although my programs mig ......

SQL SERVER:select 字符串拼接问题

一、问题
select UserID,LastName,FirstName,UserName from SYSUser
UserID LastName FirstName UserName
------------------------------------------------------
1      A        B        C
2  &nb ......

SQL统计大全收藏版 个人使用

文章来源:IT工程技术网, 全文链接:http://www.systhinker.com/html/81/n-11481.html
1.计算每个人的总成绩并排名
select name,sum(score) as allscore from stuscore group by name order by allscore
2.计算每个人的总成绩并排名
select distinct t1.name,t1.stuid,t2.allscore from stuscore t1,( select st ......

五种提高 SQL 性能的方法

本文节选自MSDN的文章《五种提高 SQL 性能的方法》,提出如何提高基于SQL Server应用程序的运行效率,非常值得推荐。对一些Traffic很高的应用系统而言,如何提高和改进SQL指令,是非常重要的,也是一个很好的突破点。
*文章主要包括如下一些内容(如感兴趣,请直接访问下面的URL阅读完整的中英文文档):
1, 从 INSERT 返 ......

db2 V8的有关SQL limits

The following tables describe certain SQL
limits. Adhering to the most restrictive case can help the programmer
design application programs that are easily portable.
Table 7. Identifier Length Limits
Description
Limit in Bytes
Longest authorization
name (can only be single-byte characters) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号