C# 从固件FW1中选择FW1.id,计数(*)。将固件FW2连接到FW1上。固件_组_id=FW2。固件_组_id和FW1.br_日期
C# 从固件FW1中选择FW1.id,计数(*)。将固件FW2连接到FW1上。固件_组_id=FW2。固件_组_id和FW1.br_日期,c#,sql,linq,C#,Sql,Linq,从固件FW1中选择FW1.id,计数(*)。将固件FW2连接到FW1上。固件_组_id=FW2。固件_组_id和FW1.br_日期
从固件FW1中选择FW1.id,计数(*)。将固件FW2连接到FW1上。固件_组_id=FW2。固件_组_id和FW1.br_日期
FW1.br_date,你会怎么做?你怎么翻译这个?@copoolse,我已经尝试过了,但对我不起作用。我很感激你的想法。但是我正在寻找Linq中的自我连接,并比较t。)他用更少的字符串来表示日期(只是出于好奇:如果在本期中有一个像这样的左连接,但在连接条件中只有条件FW1.br_date
,你会怎么做?如何翻译?
SELECT
FW1.id, count(*)
FROM
firmware FW1
LEFT JOIN
firmware FW2 ON FW1.firmware_group_id = FW2.firmware_group_id
AND FW1.br_date < FW2.br_date
AND FW2.[public]= '1'
GROUP BY
FW1.id
from f1 in firmwares
from f2 in firmwares
let f1_date = DateTime.Parse(f1.Dt)
let f2_date = DateTime.Parse(f2.Dt)
where f1.Group_Id == f2.Group_Id && f1_date < f2_date
group f1 by f1.Id into fres
select new {
Id = fres.Key,
Count = fres.Count()
};
var result = FW1.GroupJoin(FW2, // GroupJoin FW1 and FW2
fw1 => fw1.firmware_group_id, // from fw1 take the primary key firmware_group_id
fw2 => fw2.firmware_group_id, // from fw2 take the foreing key firmware_group_id
(fw1, fw2s) => new // from every fw1, with all its matching fw2s
{ // make one new object containing the following properties:
Id = fw1.Id,
// Count the fw2s of this fw1 that have public == 1
// and a date larger than fw1.date
Count = fw2.Where(fw2 => fw2.Public == 1 && fw1.br_date < fw2.br_date)
.Count(),
});