子查询连接在SQLSugar里面怎么实现 返回
SELECT a.ProductId,ISNULL(SUM(d.Quantity),0) FROM dbo.Product a LEFT JOIN ( dbo.ProductEntry b INNER JOIN dbo.ProductEntryItem c ON c.ProductEntryId = b.ProductEntryId AND b.ProductEntryStates=6 INNER JOIN dbo.ProductEntryItemDetail d ON c.ProductEntryItemId=d.ProductEntryItemId ) ON d.ProductId = a.ProductId
GROUP BY a.ProductId
假设:
Context.Queryable<Product>().LeftJoin(SqlFunc.Subqueryable<ProductEntryItemDetail>((s, d) => s.ProductId == d.ProductId).LeftJoin<ProductEntryItem>((s, d, ei) => d.ProductEntryItemId == ei.ProductEntryItemId).LeftJoin<ProductEntry>((s, d, ei, p) => p.ProductEntryId == ei.ProductEntryId && ints.Contains(p.ProductEntryStates)))
.GroupBy((s, d, ei, p) => s.ProductId)
.Select((s, d, ei, p) => new
{
s.ProductId,
Quantity = SqlFunc.IsNull(SqlFunc.AggregateSum(d.Quantity), 0)
})
热忱回答(5)
-
乘风 VIP01个月前
补充一下,我这个是手动导航里面的
0 回复 -
fate sta VIP01个月前
看文档:嵌套查询
0 回复 -
乘风 VIP01个月前
@fate sta:拆成两个吗?
0 回复 -
乘风 VIP01个月前
@fate sta:可是拆成两个,在手动导航里面不是会循环吗?
0 回复 -
乘风 VIP01个月前
...我大概懂了
0 回复