日期:2014-05-17 浏览次数:20538 次
declare @test table(股票代码 int, 股票名称 nvarchar(4),是否持仓 int, 操作时间 datetime)
insert into @test
select 20300348, N'长亮科技', 0, '2012-09-05 09:51:55.290' union all
select 20300328, N'宜安科技', 1, '2012-09-03 13:20:30.440' union all
select 20300328, N'宜安科技', 0, '2012-08-31 10:41:54.910' union all
select 20300348, N'长亮科技', 1, '2012-08-31 10:37:58.310' union all
select 20300348, N'长亮科技', 0, '2012-08-28 09:55:14.793'
;with cte as
(
select row_number() over(partition by 股票代码 order by 操作时间 desc) rn,* from @test
)
select 股票代码, 股票名称,是否持仓, 操作时间 from cte where rn=1 and 是否持仓=0
/*
股票代码 股票名称 是否持仓 操作时间
----------- ---- ----------- -----------------------
20300348 长亮科技 0 2012-09-05 09:51:55.290
*/
------解决方案--------------------
我的回答也得不到你要结果?