【发布时间】:2016-12-10 22:26:13
【问题描述】:
myTuples 有 {string id, int start, int end}
使用此示例数据:
{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
};
【问题讨论】:
-
@MauriceReeves 不确定是否重复,因为在这种情况下他想要
groupA MINUS groupB我想要groupA CROSS JOIN groupA