2009-10-22 4 views
0
select colId, 
     colTaskType, 
     MaxID 
from tblTaskType 
join (
     select tblCheckList.colTaskTypeID, 
       max(colItemNumber) MaxID 
     from tblCheckList 
     group by colTaskTypeID 
     ) x on coltaskTypeID = tblTaskType.colID 

Répondre

0

En supposant que vous utilisez linq-to-sql et avez les deux tables dans un datacontext.

plus ou moins traduction exacte serait:

var maxChecks = from checks in DataContext.tblChecklist 
       group checks by checks.colTaskTypeID into g 
       select new { colTaskTypeID, max = g.Group.Max(x => x.colItemNumber) }; 

var result = from t in DataContext.tblTaskType 
      join c in maxChecks on t.colTaskTypeID equals c.colTaskTypeID 
      select new { t.colId, t.colTaskTypeID, c.max }; 

Mais vous pouvez essayer:

var result = from t in DataContext.tblTaskType 
      select new { 
        t.colId, 
        t.colTaskTypeID, 
        Max = (from c in DataContext.tblChecklist 
          where c.colTaskTypeID == t.colTaskTypeID 
          select c.colItemNumber).Max() }; 
Questions connexes