myTuples有{string id, int start, int end}
自聯接LINQ與不等於
有了這個樣本數據:
{A, 10, 11},
{B, 20, 30},
{C, 25, 35},
{D, 25, 28},
{E, 7, 35},
結果應該是:x1 < x2 < x3 < x4
{7, 10, 11, 35} -- row id=A {10, 11} between id=E {7,35}
{7, 25, 28, 35} -- row id=D {25, 28} between id=E {7,35}
{20, 25, 28, 30} -- row id=D {25, 28} between id=B {20,30}
如果添加{F, 15, 40}
然後row=B
可以在裏面也是。
{15, 20, 30, 40} -- row id=B {20, 30} between id=F {15,40}
這就是我所嘗試的。
var query = from t1 in myTuples
join t2 in myTuples
on t1.id equals t2.id
where (t1.start > t2.start && t1.end < t2.end)
|| (t1.start < t2.start && t1.end > t2.end)
select new
{
x1 = t1.start,
x2 = t2.start,
x3 = t1.end,
x4 = t2.end
};
但我的第一個問題是沒有not equal
加入。
最後一部分並不重要,以後我可以修復它。但是我想這樣
select new
{
x1 = t1.start < t2.start : t1.start : t2.start,
x2 = t1.start < t2.start : t2.start : t1.start,
x3 = t1.end < t2.en: t1.end: t2.end,
x4 = t1.end < t2.en: t2.end: t1.end
};
http://stackoverflow.com/questions/3762869/is-there-a-not-equal-in-a-linq-join –
@MauriceReeves的可能重複不知道是否重複,因爲在那種情況下,他希望'groupA MINUS groupB'我想要'groupA CROSS JOIN groupA' –