我已经爬行了几个关于Linq-to-SQL的各种问题,涉及连接、计数、求和等。但我只是很难掌握如何做以下简单的SQL语句……
SELECT
tblTechItems.ItemName,
SUM(tblTechInventory.EntityTypeUID) AS TotalOfItemByType
FROM
tblTechInventory
INNER JOIN
tblTechItems ON tblTechInventory.ItemUID = tblTechItems.ItemUID
GROUP BY
tblTechInventory.StatusUID,
tblTechItems.ItemName,
tblTechInventory.InventoryUID
HAVING
tblTechInventory.StatusUID = 26
发布于 2010-10-14 05:09:09
试试这个:
var query = from e in db.tblTechInventory
join f in db.tblTechItems on e.ItemUID equals f.ItemUID into x
from y in x
group e by new { e.StatusUID, y.ItemName, e.InventoryUID } into g
where e.StatusUID == 26
select new {
g.Key.ItemName,
TotalOfItemByType = g.Sum(e => e.EntityTypeUID)
};
发布于 2010-10-14 05:21:46
我会试一试的。
var results = tblTechInventory
.Join(tblTechItems, i=> i.ItemUID, o => o.ItemUID, (i,o) => new {i.ItemName, o.EntityTypeUID, o.StatusUID, i.ItemName, o.InventoryUID})
.Where(o => o.StatusUID == 26)
.GroupBy(g => new {g.StatusUID, g.ItemName, g.InventoryUID}, (gr, items) => new {gr.Key.ItemName, items.Sum(i => i.EntityTypeUID)});
https://stackoverflow.com/questions/3927951
复制相似问题