Linq查询2个字段的最大值
我觉得标题有点神秘,下面是我想做的 我的选项卡中有两个datetime字段。 现在我想选择最大(即未来最远)日期大于“今天”的行Linq查询2个字段的最大值,linq,Linq,我觉得标题有点神秘,下面是我想做的 我的选项卡中有两个datetime字段。 现在我想选择最大(即未来最远)日期大于“今天”的行 few examples: (today is 6-22) date1: null, date2: null : no match, all lower than now date1: null, date2: 5-31: no match, all lower than now date1: null, date2: 6-23: match, 6-23 is lar
few examples: (today is 6-22)
date1: null, date2: null : no match, all lower than now
date1: null, date2: 5-31: no match, all lower than now
date1: null, date2: 6-23: match, 6-23 is larger than now
date1: 5-31, date2: 7-23: match, 6-23 is larger than now
date1: 7-21, date2: 1-23: match, 7-21 is larger than now
date1: 7-21, date2: null: match, 7-21 is larger than now
所以在某种伪代码中:
从表中选择*,其中(max(date2,date2))>now
问候,,
米歇尔:这就是你想要的吗(我转换了你的SQL):
这是您想要的吗(我转换了您的SQL):
我想你的意思是从表中选择*(max(date1,date2))>这是正确的,这就是我的意思:)我想你的意思是从表中选择*(max(date1,date2))>这是正确的,这就是我的意思:)如果我看这个,我会看到linq查询就在我面前。只是有时候想用Linq语句来解决这个问题比较困难。如果我看这个,我会看到Linq查询就在我面前,我想。只是有时候想用Linq语句来解决问题。
from row in table
where (row.Date1 != null && row.Date1 > DateTime.Now) ||
(row.Date2 != null && row.Date2 > DateTime.Now)
select row