当前位置: 代码迷 >> Sql Server >> SQLServer 2008一个SQL语句的有关问题,纠结了小弟我好长时间,望大神给个了断.
  详细解决方案

SQLServer 2008一个SQL语句的有关问题,纠结了小弟我好长时间,望大神给个了断.

热度:52   发布时间:2016-04-24 18:43:29.0
SQLServer 2008一个SQL语句的问题,纠结了我好长时间,望大神给个了断...
SQLServer2008 一个数据表,没有主键,让你删除这个表中数据的第N行数据。
SQL语句该怎么写。

column1  column2  column3  column4  column5
   1        2        3        4        5  
   11       22       33       44       55  
   111      222      333      444      555  
   1111     2222     3333     4444     5555  
   1111     2222    3333     4444     5555  
  删除下划线的那行
------解决方案--------------------
带出一个ID再删除
----------------------------------------------------------------
-- Author  :DBA_Huangzj(發糞塗牆)
-- Date    :2014-02-11 18:01:08
-- Version:
--      Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 
-- Dec 28 2012 20:23:12 
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[HUANG]
if object_id('[HUANG]') is not null drop table [HUANG]
go 
create table [HUANG]([column1] int,[column2] int,[column3] int,[column4] int,[column5] int)
insert [HUANG]
select 1,2,3,4,5 union all
select 11,22,33,44,55 union all
select 111,222,333,444,555 union all
select 1111,2222,3333,4444,5555 union all
select 1111,2222,3333,4444,5555
--------------开始查询--------------------------

select * ,ROW_NUMBER()OVER(ORDER BY column1)id
from [HUANG]

----------------结果----------------------------
/* 
column1     column2     column3     column4     column5     id
----------- ----------- ----------- ----------- ----------- --------------------
1           2           3           4           5           1
11          22          33          44          55          2
111         222         333         444         555         3
1111        2222        3333        4444        5555        4
1111        2222        3333        4444        5555        5
*/

------解决方案--------------------
引用:
Quote: 引用:

删除重复数据


--drop table test

create table test(
column1 int,column2 int,column3 int,column4 int,column5 int
)

insert into test
select    1        ,2        ,3        ,4        ,5     union all
select    11       ,22       ,33       ,44       ,55   union all
select    111      ,222      ,333      ,444      ,555   union all
select    1111     ,2222     ,3333     ,4444     ,5555   union all
select    1111     ,2222    ,3333     ,4444     ,5555
  相关解决方案