我有三张桌子:
TABLE_PRODUCT (IdProduct, ProductName, ProductUnit)
TABLE_STORE_HOUSE (IdContain, IdProduct, ProductNumber, TimeInput)
TABLE_SELL (IdSell, IdContain, ProductNumberSell, TimeSell)
当前,如何使用LinQ查询获取TABLE_STORE_HOUSE.IdProduct
女巫条件TABLE_STORE_HOUSE.ProductNumber - Sum(TABLE_SELL.ProductNumberSell) > 0
和TABLE_STORE_HOUSE.TimeInput
最小
帮我转换Sql到Linq ..............
select top 1 IdContain
from
TABLE_STORE_HOUSE
where IdProduct = '6'
and
ProductNumber - (select sum(ProductNumber)
from TABLE_SELL
Where TABLE_SELL.IdContain = IdContain)> 0
order by TimeInput desc;
答案 0 :(得分:1)
你能试试吗?
from t in TABLE_STORE_HOUSEs
let TSell = (
from s in TABLE_SELLs
where s.IdContain == t.IdContain
orderby s.ProductNumber
select new {
s.ProductNumber
}
)
where t.IdProduct == 6 && (t.ProductNumber - TSell.Sum(si => si.ProductNumber)) > 0
select new { t.IdContain }
对于前1名,您可以使用Take()
功能。