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

在SQL Server 删除重复数据

删除数据库表中某一字段的重复纪录,只想保留一条记录可用以下方法:
执行以下语句:
declare @max integer,@id varchar(18) --此处变量类型根据字段类型设置
declare cur_rows cursor local for select 字段,count(*) from 表名group by 字段 having count(*) > 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
 select @max = @max -1
 set rowcount @max
 delete from 表名where 字段 = @id
 fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0


相关文档:

SQL Server [分布式查询/事务]

分布式查询
    OPENROWSET
    从Excel取数据
    SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=d:\1.xls',[Sheet1$])
    从Oracle取数据
    SELECT * from OPENROWSET('MSDAORA.1','NetServiceName ......

SQL求解八皇后问题(92种结果)

--该表保存结果
create table c(c1 tinyint, c2 tinyint, c3 tinyint, c4 tinyint, c5 tinyint, c6 tinyint, c7 tinyint, c8 tinyint, c9 tinyint, c10 tinyint, c11 tinyint, c12 tinyint, c13 tinyint, c14 tinyint, c15 tinyint, c16 tinyint, c17 tinyint, c18 tinyint, c19 tinyint, c20 tinyint, c21 tinyint, c22 t ......

pl/sql 语句的几点优化

1.
     SQL> desc gjh_a05 ;
Name  Type          Nullable Default Comments
----- ------------- -------- ------- --------
A0500 VARCHAR2(2)   Y           &nbs ......

对pl/sql 语句的优化(上集)

对这个进行优化
select n5001 门店,n5002 部门,n5004 小分类,n5019 商品编码,c01d21 商品名称,
nvl(xse,0)-nvl(dzxs,0) 销售,
mle 毛利,
nvl(xl,0)-nvl(dzsl,0) 销量
 from
(select n5001,n5002,n5004,n5019,sum(n5011) xse,sum(n5016) mle,sum(n5023) xl
from n50
where to_char(n5010,'yyyymmdd')>='20 ......

SQL精华收集

order by 的数值型灵活使用
select * from table_a where id=p_id order by decode(函数,'asc',1,'desc',-1)*jsny;
控制试图的访问时间:
6.create view ...
as
select ... from where exists(select x from dual where sysdate>=8:00am and sysdate<=5:00pm)
妙用decode实现排序
select * from tabnam ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号