sql语句查询出表⾥符合条件的第⼆条记录的⽅法创建⽤到的表的SQL
CREATE TABLE [dbo].[emp_pay](
[employeeID] [int] NOT NULL,
[base_pay] [money] NOT NULL,
[commission] [decimal](2, 2) NOT NULL
) ON [PRIMARY]
⽣成的表,及表中的数据:
--⽅法⼀
select top 1 * from
(
SELECT TOP 2 *
FROM [dbo].[emp_pay]
WHERE base_pay = 500
order by employeeID ASC) as a --注意:派⽣表后⾯⼀定要指定别名.
order ployeeID DESC
--⽅法⼆
select IDENTITY(int,1,1) ID,* INTO #Temp from [dbo].[emp_pay] where base_pay = 500
select * from #Temp where ID =2
drop Table #Temp
sql语句查询不包含--⽅法三
set rowcount 2
SELECT * into #t from [dbo].[emp_pay] where base_pay = 500
set rowcount 1
delete from #t
select * from #t
set rowcount 0
drop table #t
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论