我有以下 SQL 查询:
SELECT Devices.*
, DevicesActivityData.*
FROM Devices
INNER JOIN DevicesActivityData
ON Devices.ID = DevicesActivityData.DeviceID
WHERE DevicesActivityData.DeviceDateTime IN (
SELECT MAX(DevicesActivityData.DeviceDateTime) AS MaxDate
FROM DevicesActivityData
GROUP BY DevicesActivityData.DeviceID
)
我需要完成我的代码:
var Q = db.Devices.Join(
db.DevicesActivityDatas,
d => d.ID,
a => a.DeviceID,
(d, a) => new { d.ID,d.DeviceName,a.DeviceDateTime }
);
我在最后一部分有问题选择最大值
如何将此部分添加到我的查询中......
[where DevicesActivityData.DeviceDateTime in ( select max(DevicesActivityData.DeviceDateTime) as MaxDate from DevicesActivityData group by DevicesActivityData.DeviceID )]