我正在尝试将此SQL查询转换为LINQ语法,但很难。 有人可以帮助我吗?
SELECT *
FROM
(SELECT
DESCR,
SUM(CONSUMPTIONCOST) AS CUSUMPTIONCOST,
SUM(SCHEDULEDREPAIRCOST) AS SCHEDULEDREPAIRCOST,
SUM(PALS) AS PALSUM,
SUM(UNSCHEDULEDREPAIRCOST) AS UNSCHEDULEDREPAIRCOST,
SUM(O_S_Price) AS O_S_PRICE_SUM,
SUM(PALS) AS PALS,
SUM(CGAI_TOTAL) AS CGAI_TOTAL,
SUM(SE_TOTAL) AS SE_TOTAL,
SUM(MISCADDER_TOTAL) AS MISCADDER_TOTAL,
SUM(CODB_TOTAL) AS CODB_TOTAL,
SUM(OS_PRICE_PLUSFACTORS) AS OS_PRICE_PLUSFACTORS,
SUM(PALS + O_S_PRICE) AS COST,
RANK() OVER(ORDER BY SUM(PALS + O_S_PRICE) DESC) AS COST_RANK
FROM
jamResult.Parts_Ace
GROUP BY
DESCR, RUN_NAME) AS X
WHERE
COST_RANK > 0
AND COST_RANK < 10
ORDER BY
COST_RANK ASC
答案 0 :(得分:0)
如果你正在寻找0到10之间的COST_RANK
值(前9个结果按成本排名降级 - 排名为1到9的那些),你可以OrderByDescending
进行LINQ,然后是Take(9)
以缩小结果集:
var result = yourQuery.OrderByDescending(x => x.Cost).Take(9);