# 如何根据desc的devicetimestamp顺序从每个表中获取前1条记录

sql

`````` select top 1 * from [TransTrak_V_1.0].[dbo].[Current_Voltage] as cv
inner join [TransTrak_V_1.0].[dbo].[Overview]  as o
on cv.DeviceImei = o.DeviceImei
inner join [TransTrak_V_1.0].[dbo].[Power]  as p
on cv.DeviceImei = p.DeviceImei
inner join [TransTrak_V_1.0].[dbo].[PowerFactor]  as pf
on cv.DeviceImei = pf.DeviceImei
inner join [TransTrak_V_1.0].[dbo].[Total_Power]  as tp
on cv.DeviceImei = tp.DeviceImei
where cv.DeviceImei='8673220311'
order by cv.DeviceTimeStamp desc

``````

``````select top 1 * from [TransTrak_V_1.0].[dbo].[Current_Voltage] as cv
inner join (
Select top 1 * from [TransTrak_V_1.0].[dbo].[Overview] o
where cv.DeviceImei='8673220311'
order by o.DeviceTimeStamp desc
) as o ON 1=1
inner join (
Select top 1 * from [TransTrak_V_1.0].[dbo].[Power] p
where p.DeviceImei='8673220311'
order by p.DeviceTimeStamp desc
) as p ON 1=1
inner join (
Select top 1 * from [TransTrak_V_1.0].[dbo].[PowerFactor] pf
where pf.DeviceImei='8673220311'
order by pf.DeviceTimeStamp desc
) as p ON 1=1
inner join (
Select top 1 * from [TransTrak_V_1.0].[dbo].[Total_Power] tp
where tp.DeviceImei='8673220311'
order by tp.DeviceTimeStamp desc
) as tp ON 1=1
where cv.DeviceImei='8673220311'
order by cv.DeviceTimeStamp desc
``````

0条评论