需要 Linq 翻译以下 SQL 查询

发布于 2024-08-08 03:13:30 字数 299 浏览 8 评论 0原文

select  colId,
        colTaskType,
        MaxID
from    tblTaskType
join    (
         select tblCheckList.colTaskTypeID,
                max(colItemNumber) MaxID
         from   tblCheckList
         group by colTaskTypeID
        ) x on coltaskTypeID = tblTaskType.colID
select  colId,
        colTaskType,
        MaxID
from    tblTaskType
join    (
         select tblCheckList.colTaskTypeID,
                max(colItemNumber) MaxID
         from   tblCheckList
         group by colTaskTypeID
        ) x on coltaskTypeID = tblTaskType.colID

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖阳 2024-08-15 03:13:30

假设您正在使用 linq-to-sql 并在数据上下文中有两个表。

或多或少准确的翻译是:

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 };

但你可以尝试:

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() };

Assuming you are using linq-to-sql and have the two tables in a datacontext.

The more or less exact translation would be:

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 };

But you could try:

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() };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文