select PerInfo.*,RGD.*,DV.* from (select * from dbo.G_PersionInfo g where 1=1 and GpsID<>'' )PerInfo
left join
(
select d.* from dbo.Device d
where not exists
(
select 1 from dbo.Device where GpsID=d.GpsID and ID>d.ID
)
)DV
on PerInfo.GpsID=DV.GpsID
left join
(
select r.* from dbo.ReceiveGpsData r
where not exists
(
select 1 from dbo.ReceiveGpsData where GpsID=r.GpsID and ID>r.ID
)
)RGD
on PerInfo.GpsID=RGD.GpsID
left join
(
select d.* from dbo.Device d
where not exists
(
select 1 from dbo.Device where GpsID=d.GpsID and ID>d.ID
)
)DV
on PerInfo.GpsID=DV.GpsID
left join
(
select r.* from dbo.ReceiveGpsData r
where not exists
(
select 1 from dbo.ReceiveGpsData where GpsID=r.GpsID and ID>r.ID
)
)RGD
on PerInfo.GpsID=RGD.GpsID