34,590
社区成员
发帖
与我相关
我的任务
分享
declare @tb table (kh int,rq datetime,flag varchar(20))
insert into @tb select 1,'2008-01-01','进口机'
insert into @tb select 1,'2008-01-02','出口机'
insert into @tb select 2,'2008-01-03','进口机'
insert into @tb select 2,'2008-01-04','出口机'
select kh,
max(case when flag='进口机' then rq end) as '进口日期',
max(case when flag='出口机' then rq end) as '出口日期'
from @tb
group by kh