SQL Group By 的 LINQ/Lambda 查询帮助最大限度?
我想知道是否有人可以帮助我根据以下 SQL 查询进行 lambda 或 LINQ 查询(最好是 lambda)。我已经尝试并取得了一些进展,但没有成功:(
SELECT TOP 1 MAX(cv.ProductID) as MaxProductID, MAX(ap.RegionAsLocationID) RegionID,
COUNT(cv.ProductID) as ProductCount
FROM CustomerVouchers cv
INNER JOIN Products p on p.id = cv.ProductID and p.status = 3
INNER JOIN APs ap on ap.id = p.apid
WHERE cv.Status = 1
GROUP BY cv.ProductID
ORDER BY ProductCount DESC
SQL 返回这样的结果:
MaxProductID | RegionID | ProductCount
123 | 16862 | 3
我在“最大结果”列之后,其中 MAX()
将是客户凭证记录,它是找到最多productID 的关系,
谢谢大家。
I was wondering if anybody could help me with a lambda or LINQ query (preferrably lambda) based off the following SQL query. I have tried and got a little way through but no luck :(
SELECT TOP 1 MAX(cv.ProductID) as MaxProductID, MAX(ap.RegionAsLocationID) RegionID,
COUNT(cv.ProductID) as ProductCount
FROM CustomerVouchers cv
INNER JOIN Products p on p.id = cv.ProductID and p.status = 3
INNER JOIN APs ap on ap.id = p.apid
WHERE cv.Status = 1
GROUP BY cv.ProductID
ORDER BY ProductCount DESC
The SQL returns a result like this:
MaxProductID | RegionID | ProductCount
123 | 16862 | 3
I am after the "max result" columns where MAX()
would be the customer vouchers record and it's relationships which has the most productID's found.
Thanks gang.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 ctx 是您的实体模型,请使用以下内容。
Assuming ctx is your entity model, use the following.