27,579
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据: #tb
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb (resourceId int,country varchar(5),year int,month int,value int)
insert into #tb
select 1,'china',2009,1,1 union all
select 1,'china',2010,5,3 union all
select 1,'china',2009,10,2 union all
select 2,'china',2010,1,6
select top 1 * from #tb
where resourceId =1 and country='china'
order by ltrim(year)+'-'+ltrim(month)+'-01' desc
resourceId country year month value
----------- ------- ----------- ----------- -----------
1 china 2010 5 3
(1 行受影响)
select top 1*
from a
order by year desc,month desc,value desc