SQL ÈçºÎɾ³ýÊý¾Ý±íÖÐÖظ´µÄÊý¾Ý£¿
¡¾ÒýÓãºÃÍáï¼¼ÊõÎÄÕÂÕªÒª
¡¿
¾²âÊÔ£¬·½·¨¶þ¿É³É¹¦É¾³ýÊý¾Ý£¬·½·¨Ò»¡¢Èý ɾ³ýÊý¾Ýʧ°Ü¡£Çë·¹ýµÄÅóÓÑ£¬Ö¸µãÃÔ½ò¡£¡£¡£
ÎÊÌ⣺һ¸ö±íÓÐ×ÔÔöµÄID
ÁУ¬±íÖÐÓÐһЩ¼Ç¼ÄÚÈÝÖظ´£¬Ò²¾ÍÊÇ˵ÕâЩ¼Ç¼³ýÁËID
²»Í¬Ö®Í⣬ÆäËûµÄÐÅÏ¢¶¼Ïàͬ¡£ÐèÒª°ÑÖظ´µÄ¼Ç¼±£ÁôÒ»Ìõ£¬Ê£ÏµÄɾ³ý
·½·¨Ò»£º»¹ÊÇ2000
ÄêµÄʱºòһλOracle
DBA
½Ðm.l·¢¸ø¼¼Êõ²¿È«ÌåµÄ£¨¿ÉϧÔʼÓʼþÕÒ²»µ½ÁË£¬Òª²»È»ÎÒµ±ÎÄÎï·¢¸ø´ó¼Ò£©£º
delete from Score
where [sid] not in (
select min([sid])
from Score
group by [sid],[sname],[score])
·½·¨¶þ£ºz.benÔÚÍøÂçÉÏËѳöÀ´µÄ£º
--
ɾ³ýÏàͬ³ÇÊÐϵÄÏàͬÐÐÕþÇø
delete a from Score a
where a.sid>(
select min(sid) from Score b
where a.sname=b.sname and a.score=b.score)
·½·¨Èý£ºÊ¹ÓÃsql
2005
ÐÂÔöµÄrow_number()
¹¦ÄܺÍwith
¹Ø¼ü×Ö£¬ÎÒÊÇ´ÓÕÔÁ¢¶«ÄÇÀïѧÀ´µÄ¡£
print('ɾ³ýScore±íÖÐÖظ´µÄ¼Ç¼')
;WITH a AS (
SELECT ROW_NUMBER() OVER (PARTITION BY [sid],[sname],[score]
ORDER BY [sid],[sname],[score]) AS rn,*
from Score
)
delete from a WHERE a.rn>1
------------------------------------------------------------------------------
¸½Â¼£ºÊý¾Ý¿â±í½Å±¾
USE [DBtest]
GO
/****** Object: Table [dbo].[Score] Script Date: 01/13/2010 23:47:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Score](
[sid] [int] IDENTITY(1,1) NOT NULL,
[sname] [nchar](10) NOT NULL,
[score] [nchar](10) NOT NULL,
CONSTRAINT [PK_Score] PRIMARY KEY CLUSTERED
(
[sid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Êý¾ÝÌî³ä£º
1
aa
bb
2
bb
cc
3
cc
dd
Ïà¹ØÎĵµ£º
Ö´ÐÐÊý¾Ý²Ù×÷ʱ£¬ÓÉÓÚÆ´½ÓSQL´æÔÚÖÖÖֱ׶ˣ¬Ôç¾ÍÓ¦¸ÃÅ×ÆúÁË£¬µ«ÔÚÏÖʵ¿ª·¢Ê±£¬ÓÖÓÉÓÚÖÖÖÖÔÒò£¬¹«Ë¾Ò»Ö±²ÉÓÃÕâÖÖ·½Ê½£¨UI²ãºÍÂß¼²ã¶¼ÓÐÑϸñµÄ¹ýÂË£¬µ¹Ò²Ã»³öÏÖ¹ýʲôÎÊÌ⣩£¬µ«×òÌ쿪·¢Ê±È´³öÏÖÁËÒâÏë²»µ½µÄÎÊÌ⣬һ¸ö¼òµ¥µÄÓï¾ä»áÔì³ÉÑÏÖغó¹û¡£¼òµ¥µÄÓï¾äʾÀýÈçÏ£º
/// <summary>
&nb ......
----start
SQL(Structured Query Language)£¬Ò²¾ÍÊǽṹ»¯²éѯÓïÑÔ£¬Ëü±»Éè¼ÆÓÃÀ´²Ù×÷¼¯ºÏµÄ£¬ÊǷǹý³Ì»¯µÄÓïÑÔ¡£Ëæ×ÅÓ¦ÓóÌÐòµÄ·¢Õ¹£¬ÒµÎñÂß¼Ô½À´Ô½¸´ÔÓ£¬´«Í³µÄSQLÒѾ²»ÄÜÂú×ãÈËÃǵÄÒªÇó£¬ÓÚÊÇÈËÃǶÔSQL½øÐÐÁËÀ©Õ¹£¬Ê¹Ëü¾ßÓÐÁ˹ý³Ì»¯µÄÂß¼£¬¼´£ºSQL PL¡£SQL PLµÄÈ«³ÆÊÇ SQL Procedural Language£ ......
For SQL Server2008:
http://www.microsoft.com/downloads/details.aspx?FamilyID=0e6168b0-2d0c-4076-96c2-60bd25294a8e&displaylang=en
For SQL Server2005:
http://www.microsoft.com/downloads/details.aspx?familyid=C6F14640-DA22-4604-AAAA-A45DE4A0CD4A&displaylang=en ......
Ñ¡Ôñ×Ô CSDN
SQLÓï¾äµ¼Èëµ¼³ö´óÈ«
/******* µ¼³öµ½excel
EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:\temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""'
/*********** µ¼ÈëExcel
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\tes ......
ÔÚSQL Server 2008ÖУ¬²»½ö¶ÔÔÓÐÐÔÄܽøÐÐÁ˸Ľø£¬»¹Ìí¼ÓÁËÐí¶àÐÂÌØÐÔ£¬±ÈÈçÐÂÌíÁËÊý¾Ý¼¯³É¹¦ÄÜ£¬¸Ä½øÁË·ÖÎö·þÎñ£¬±¨¸æ·þÎñ£¬ÒÔ¼°Office¼¯³ÉµÈµÈ¡£
¡¡¡¡SQL Server¼¯³É·þÎñ
¡¡
¡¡SSIS(SQL Server¼¯³É·þÎñ)ÊÇÒ»¸öǶÈëʽӦÓóÌÐò£¬ÓÃÓÚ¿ª·¢ºÍÖ´ÐÐETL(½âѹËõ¡¢×ª»»ºÍ¼ÓÔØ)°ü¡£SSIS´úÌæÁËSQL
2000µÄDTS¡£ÕûºÏ·þÎñ¹¦ÄܼȰü ......