use tempdb
go
select *
into #temp
from
(select 'apple' as product, '2008-10-02' as saledate, 87 as qty
union all select 'apple', '2008-10-03', 34
union all select 'apple', '2008-11-17', 75
union all select 'orange', '2008-11-01', 22
union all select 'orange', '2008-11-08', 10) x
select *
from #temp
select 'Last date record' as msg, *
from #temp
where product + '@' + convert(varchar, saledate, 120) in
(select max(product + '@' + convert(varchar, saledate, 120))
from #temp
group by product)
drop table #temp
get last date record of each product
最新推荐文章于 2024-07-30 14:18:44 发布