我的 SQL 查詢看起來像這樣:SQL 查詢回傳與存在的每個 colorwayid 關聯的收入
select p.colorwaysid,sum(oivs.actItemvalue oivs.custom) as revenue
from Product p inner join eshakti_corp..orderitemvaluesplit oivs on p.productid = oivs.productid
inner join eshakti_corp..orders o on oivs.orderid = o.orderid
where colorwaysid is not null and o.crdate >= '4/1/2022' and o.crdate <= '4/30/2022'
group by p.colorwaysid order by revenue desc
到目前為止,我已經在 LINQ C# 中完成了這項作業
from product in eshaktiDb.Products
join oivs in corpDb.OrderitemvalueSplits on product.ProductId equals oivs.Productid
join order in corpDb.Orders on oivs.Orderid equals order.OrderID
where product.ColorWaysId != null && order.CrDate >= fromDate && order.CrDate <= toDate
請幫助我創建完整的 Linq 查詢。謝謝!
uj5u.com熱心網友回復:
group by部分很明顯:
var query =
from product in eshaktiDb.Products
join oivs in corpDb.OrderitemvalueSplits on product.ProductId equals oivs.Productid
join order in corpDb.Orders on oivs.Orderid equals order.OrderID
where product.ColorWaysId != null && order.CrDate >= fromDate && order.CrDate <= toDate
group ovis by p.colorwaysid into g
select new
{
colorwaysid = g.Key,
revenue = g.Sum(o => o.actItemvalue o.custom)
};
請注意,如果您已正確配置導航屬性,則可以省略連接。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/472708.html
上一篇:C#中的方法多載
