with A as
(
select 'A' as Col1,20 as Col2
union all
select 'B',30
union all
select 'C',40
)
,B as
(
select 'A' as Col1,20 as Col2,'2015-12-1' as Col3
union all
select 'B',30,'2015-12-1'
union all
select 'C',40,'2015-11-1'
union all
select 'A',10,'2015-10-1'
union all
select 'A',20,'2015-10-1'
)
select A.Col1,B.Col2,max(B.Col3) Col3
from A
join B on a.Col1 = b.Col1
group by A.Col1,B.Col2
order by A.Col1
1 个回复
悟 - 取是能力,舍是境界 2015-12-21 回答
赞同来自: