如何在不使用order

编程入门 行业动态 更新时间:2024-10-23 17:23:49
本文介绍了如何在不使用order_number()和不使用row_number()的情况下选择sql server中的第n行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 任何人都可以告诉我如何在不使用row_number()的情况下选择sql server 中的 nth 行/ b>和不使用order by。 也不使用游标。(游标可以是解决方案之一,但是当有lacs时它会降低性能记录。) 提前感谢...

解决方案

从TableName中选择* ColumnName =(从TableName中选择MAX(ColumnName))

选择第n行不使用rwo_number()&命令和光标: 这里用顶部'n'代替前5名 声明 @ NewId bigint , @ NewFname varchar ( 20 ), @ NewLname varchar ( 20 ), @ NewSalary money select top 5 @ NewId = eid, @ NewFname = fname @NewLname = lname,@ NewSalary = salary from Tbl_Emp_Detail 选择 @ NewId , @ NewFname , @ NewLname , @ NewSalary

声明 @ NewId bigint 选择 top 5 @ NewId = eid 来自 Tbl_Emp_Deatail 选择 * 来自 Tbl_Emp_Detail 其中 eid = @ NewId

Hi there, Can anybody tell me how to select nth row in sql server without using row_number() and without using order by. Also without using cursors.(cursor can be one of the solution, but it decreases the performance when there are lacs of records.) thanks in advance...

解决方案

Select * From TableName Where ColumnName = (Select MAX(ColumnName) From TableName)

To select the nth row without using rwo_number()& order by and cursor : Here replace top 5 by top 'n'

declare @NewId bigint,@NewFname varchar(20),@NewLname varchar(20),@NewSalary money select top 5 @NewId =eid,@NewFname = fname @NewLname=lname,@NewSalary=salary from Tbl_Emp_Detail select @NewId ,@NewFname,@NewLname,@NewSalary

OR

declare @NewId bigint select top 5 @NewId=eid from Tbl_Emp_Deatail select * from Tbl_Emp_Detail where eid=@NewId

更多推荐

如何在不使用order

本文发布于:2023-10-18 12:56:00,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   order

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!