Converting SQL query to Lambda.

huangapple go评论64阅读模式
英文:

Converting SQL query to Lambda

问题

SELECT a.assembly_name,
a.financial_year,
a.total_expenditure,
SUM(b.ac_bill_amount) AS TOTAL_AC_BILL
FROM fund_allotment AS a INNER JOIN mla_ac_bill AS b
ON a.assembly_name = b.assembly_name and a.financial_year = b.financial_year
GROUP BY a.assembly_name,a.financial_year,a.total_expenditure

英文:

Can anyone help me translate the below sql to lambda?

SELECT a.assembly_name,
	a.financial_year,
	a.total_expenditure,
	SUM(b.ac_bill_amount) AS TOTAL_AC_BILL
	FROM fund_allotment AS a INNER JOIN mla_ac_bill AS b
	ON a.assembly_name = b.assembly_name and a.financial_year = b.financial_year
	GROUP BY a.assembly_name,a.financial_year,a.total_expenditure

答案1

得分: 0

Here is the translated code:

var result = fundAllotment
    .Join(mlaAcBill,
        a => new { a.AssemblyName, a.FinancialYear },
        b => new { b.AssemblyName, b.FinancialYear },
        (a, b) => new
        {
            a.AssemblyName,
            a.FinancialYear,
            a.TotalExpenditure,
            b.AC_Bill_Amount
        })
    .GroupBy(x => new
    {
        x.AssemblyName,
        x.FinancialYear,
        x.TotalExpenditure
    })
    .Select(g => new
    {
        g.Key.AssemblyName,
        g.Key.FinancialYear,
        g.Key.TotalExpenditure,
        TotalACBill = g.Sum(x => x.AC_Bill_Amount)
    });

Is there anything else you would like to translate?

英文:
var result = fundAllotment
    .Join(mlaAcBill,
        a => new { a.AssemblyName, a.FinancialYear },
        b => new { b.AssemblyName, b.FinancialYear },
        (a, b) => new
        {
            a.AssemblyName,
            a.FinancialYear,
            a.TotalExpenditure,
            b.AC_Bill_Amount
        })
    .GroupBy(x => new
    {
        x.AssemblyName,
        x.FinancialYear,
        x.TotalExpenditure
    })
    .Select(g => new
    {
        g.Key.AssemblyName,
        g.Key.FinancialYear,
        g.Key.TotalExpenditure,
        TotalACBill = g.Sum(x => x.AC_Bill_Amount)
    });

答案2

得分: 0

以下是翻译好的部分:

在我看来,你想要这个:

	from fa in fund_allotment
	join mab in mla_ac_bill
		on new { fa.assembly_name, fa.financial_year }
		equals new { mab.assembly_name, mab.financial_year }
	group mab.ac_bill_amount
		by new { fa.assembly_name, fa.financial_year, fa.total_expenditure }
		into g
	select new
	{
		g.Key.assembly_name,
		g.Key.financial_year,
		g.Key.total_expenditure,
		TOTAL_AC_BILL = g.Sum()
	};
英文:

It seems to me that you want this:

from fa in fund_allotment
join mab in mla_ac_bill
	on new { fa.assembly_name, fa.financial_year }
	equals new { mab.assembly_name, mab.financial_year }
group mab.ac_bill_amount
	by new { fa.assembly_name, fa.financial_year, fa.total_expenditure }
	into g
select new
{
	g.Key.assembly_name,
	g.Key.financial_year,
	g.Key.total_expenditure,
	TOTAL_AC_BILL = g.Sum()
};

huangapple
  • 本文由 发表于 2023年6月29日 14:20:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578488.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定