我有一张桌子,我需要检索第二行的身份证。 如何实现这一目标?
缩略语 我选择了两行,但我需要。 第二行
我有一张桌子,我需要检索第二行的身份证。 如何实现这一目标?
缩略语 我选择了两行,但我需要。 第二行
假设2005年服务器+获得just的一个实例 第二行(我认为你可能会问——也是为什么要打<条码>。 赢得你们的工作?
set statistics io on
;with cte as
(
select *
, ROW_NUMBER() over (order by number) as rn
from master.dbo.spt_values
)
select *
from cte
where rn = 2
/* Just to add in what I was running RE: Comments */
;with cte as
(
select top 2 *
, ROW_NUMBER() over (order by number) as rn
from master.dbo.spt_values
)
select *
from cte
where rn = 2
在2012年+服务器中,你可以使用FSET。 FETCH:
SELECT
<column(s)>
FROM
<table(s)>
ORDER BY
<sort column(s)>
OFFSET 1 ROWS -- Skip this number of rows
FETCH NEXT 1 ROWS ONLY; -- Return this number of rows
如果外地身份证是独一无二的,则不需要增加功能。
SELECT TOP 1 *
FROM (
SELECT TOP 2 *
FROM yourTable
ORDER BY ID
) z
ORDER BY ID DESC
使用ROW_NUMBER()
到编号上,但只使用TOP
处理头两条。
尝试:
DECLARE @YourTable table (YourColumn int)
INSERT @YourTable VALUES (5)
INSERT @YourTable VALUES (7)
INSERT @YourTable VALUES (9)
INSERT @YourTable VALUES (17)
INSERT @YourTable VALUES (25)
;WITH YourCTE AS
(
SELECT TOP 2
*, ROW_NUMBER() OVER(ORDER BY YourColumn) AS RowNumber
FROM @YourTable
)
SELECT *
FROM YourCTE
WHERE RowNumber=2
OUTPUT:
YourColumn RowNumber
----------- --------------------
7 2
(1 row(s) affected)
页: 1
SELECT id
FROM tablename
ORDER BY column
OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY;
<>光>
OFFSET can only be used with ORDER BY clause. It cannot be used on its own.
OFFSET value must be greater than or equal to zero. It cannot be negative, else return error.
The OFFSET argument is used to identify the starting point to return rows from a result set. Basically, it exclude the first set of records.
The FETCH argument is used to return a set of number of rows. FETCH can’t be used itself, it is used in conjuction with OFFSET.
我猜想你重新使用2005年或更长时间。 第2行选择上2行,使用<代码>。 ROW_COUNT DESC将第二行安排为第一行,然后使用TOP 1选定。
SELECT TOP 1 COLUMN1, COLUMN2
from (
SELECT TOP 2 COLUMN1, COLUMN2
FROM Table
) ORDER BY ROW_NUMBER DESC
with T1 as
(
select row_number() over(order by ID) rownum, T2.ID
from Table2 T2
)
select ID
from T1
where rownum=2
Use TOP 2
in the SELECT to get the desired number of rows in output.
This would return in the sequence the data was created. If you have a date option you could order by the date along with TOP n
Clause.
• 接上2行;
SELECT TOP 2 [Id] FROM table
A. 某些外地接通2号最高行
SELECT TOP 2 [ID] FROM table ORDER BY <YourColumn> ASC/DESC
仅取得第二位罗;
WITH Resulttable AS
(
SELECT TOP 2
*, ROW_NUMBER() OVER(ORDER BY YourColumn) AS RowNumber
FROM @Table
)
SELECT *
FROM Resultstable
WHERE RowNumber = 2
www.un.org/Depts/DGACM/index_french.htm 英文/法文版 请让我再谈两句。
但是,你将必须特别注意条令的<编码>条款,因为这将决定第1和第2行的退还。
如果将问题改变为:
http://www.ohchr.org。
你们可以有两行。 您将不得不按发言顺序决定哪一栏。
我的路比上述路要容易得多。
DECLARE @FirstId int, @SecondId int
SELECT TOP 1 @FirstId = TableId from MyDataTable ORDER BY TableId
SELECT TOP 1 @SecondId = TableId from MyDataTable WHERE TableId <> @FirstId ORDER BY TableId
SELECT @SecondId
当然,如果你简单地想要2号邮局,那么如果你需要的话,就可以与这些价值观做些什么,那么,它就会使用ROW_NUMBER。 这将使你能更多地控制你想要选择的行文。
页: 1 我这样做并不肯定,如果在选择中,执行部分第2段只是简单。 (我可能错!)
-- Get first row, same as TOP 1
SELECT [Id] FROM
(
SELECT [Id], ROW_NUMBER() OVER (ORDER BY [Id]) AS Rownumber
FROM table
) results
WHERE results.Rownumber = 1
-- Get second row only
SELECT [Id] FROM
(
SELECT [Id], ROW_NUMBER() OVER (ORDER BY [Id]) AS Rownumber
FROM table
) results
WHERE results.Rownumber = 2
SELECT *
FROM (
SELECT top 3 *
, ROW_NUMBER() OVER (ORDER BY [newsid] desc) AS Rownumber
FROM news
where (news_type in(2,12))
) results
WHERE results.Rownumber = 1
www.un.org/Depts/DGACM/index_spanish.htm 页 次
这也是有用的:
SELECT t.*
FROM (
SELECT e1.*
, row_number() OVER (ORDER BY e1.Rate DESC) AS _Rank
FROM
HumanResources.EmployeePayHistory AS e1
) AS t
WHERE t._Rank = 2
有一个相对简单的解决方案,它依据的是Kumver和Taha Ali的评论。
想象一下,有一套包含域名的域名,按功能类别检索,不需要域名。
初步办法
DECLARE @Login NVARCHAR(100)
SELECT @Login = domainusername
-- SELECT @Login = ORIGINAL_LOGIN()
SELECT
VALUE
FROM
STRING_SPLIT(@Login, )
returns a table having 2 rows. First row holds the domain and second row holds the requested username.
使用
DECLARE @Login NVARCHAR(100)
SELECT @Login = domainusername
-- SELECT @Login = ORIGINAL_LOGIN()
SELECT
VALUE
FROM
STRING_SPLIT(@Login, )
ORDER BY
(SELECT NULL)
OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY;
确切地说,第二行从临时桌上返回。
另一种想法是:
SELECT MIN(id) FROM
(
SELECT TOP 2(TAB.[id])
FROM TAB
where TAB.field1 =3
ORDER BY TAB.[creationDate] DESC
) AS TEST
)
select *
from (
select ROW_NUMBER() OVER (ORDER BY Column_Name) as ROWNO, *
from Table_Name
) Table_Name
where ROWNO = 2
SELECT TOP 2 [Id] FROM table
I ve got two tables: TableA Col1 Col2 TableB Col3 Col4 I want to join them together: SELECT * from TableA join TableB ON (...) Now, in place of ... I need to write an expression ...
TSQL query to select all records from Customer that has an Order and also select all records from customer that does not have an Order. The table Customer contains a primary key of CustomerID. The ...
I have a stored procedure which takes an XML parameter and inserts the data into multiple tables. If I run the stored procedure into a database using a SSMS query window, everything works fine. ...
Have a win 2003 box with MSSQL 2005 running on it. There is a database which is populated every morning with new/modified SalesOrder made the previous day. The database has several tables: SalesOrder, ...
I have a table with the following fields Id Name IsPublic i need to write a sql query that updates IsPublic to false where name has a duplicate. Only one of the duplicates should have IsPublic = ...
I have a Transact-SQL query that uses the IN operator. Something like this: select * from myTable where myColumn in (1,2,3,4) Is there a way to define a variable to hold the entire list "(1,2,3,4)"? ...
I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...
I m trying to transform the SQL Query below into Linq to SQL select Categorias.IdCategoria, Categorias.Nome, SUM(lancamentos.valor) from lancamentos left outer join Categorias on Lancamentos....