2011-01-27 45 views

回答

1

没有你的DB模式

SELECT x.contentobjectid, Min(x.city) as city, temp.startdate 
from calendarentry as x 
    inner join (select contentobjectid, startdate from calendarentry where startdate > getdate() group by contentobjectid, startdate) as temp 
    on temp.contentobjectid = x.contentobjectid 
group by x.contentobjectid, temp.startdate 

IM它很难真正得到这个权利,但尽我已经写为出发点。另外,我强烈建议下载LINQPad,并支付30美元的智能感知支持!

var result = (
from c1 in calendarentry 
let grp = (from c2 in calendarentry 
      where c2.contentobjectid = c1.contentopjectid && 
        c2.startdate > DateTime.Now 
      group c2 by new { contentobjectid = c2.contentobjectid, startdate = c2.startdate } into g 
      select g) 
select new { 
     contentobjectid = c1.contentobjectid, 
     city = c1.Min(x => x.city), 
     startdate = grp.startDate 
     });