Quantcast
Channel: SQL.ru: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 7251

получить бижайшую дату (из прошлого)

$
0
0
необходимо получить из installations параметры assy на ближайшую дату
как-то красивше возможно?
insert installations (date,assy)
select '20170101',1
union all
select '20170202',2

insert params (date,param1)
select '20170105',100
union all
select '20170203',200

select p.*,i.* 
from params p 
cross apply 
	(select top(1) * 
		from installations i 
			where i.date<=p.date order by date desc) i

Viewing all articles
Browse latest Browse all 7251

Trending Articles