Converting SQL query to Lambda.

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

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?

  1. SELECT a.assembly_name,
  2. a.financial_year,
  3. a.total_expenditure,
  4. SUM(b.ac_bill_amount) AS TOTAL_AC_BILL
  5. FROM fund_allotment AS a INNER JOIN mla_ac_bill AS b
  6. ON a.assembly_name = b.assembly_name and a.financial_year = b.financial_year
  7. GROUP BY a.assembly_name,a.financial_year,a.total_expenditure

答案1

得分: 0

Here is the translated code:

  1. var result = fundAllotment
  2. .Join(mlaAcBill,
  3. a => new { a.AssemblyName, a.FinancialYear },
  4. b => new { b.AssemblyName, b.FinancialYear },
  5. (a, b) => new
  6. {
  7. a.AssemblyName,
  8. a.FinancialYear,
  9. a.TotalExpenditure,
  10. b.AC_Bill_Amount
  11. })
  12. .GroupBy(x => new
  13. {
  14. x.AssemblyName,
  15. x.FinancialYear,
  16. x.TotalExpenditure
  17. })
  18. .Select(g => new
  19. {
  20. g.Key.AssemblyName,
  21. g.Key.FinancialYear,
  22. g.Key.TotalExpenditure,
  23. TotalACBill = g.Sum(x => x.AC_Bill_Amount)
  24. });

Is there anything else you would like to translate?

英文:
  1. var result = fundAllotment
  2. .Join(mlaAcBill,
  3. a => new { a.AssemblyName, a.FinancialYear },
  4. b => new { b.AssemblyName, b.FinancialYear },
  5. (a, b) => new
  6. {
  7. a.AssemblyName,
  8. a.FinancialYear,
  9. a.TotalExpenditure,
  10. b.AC_Bill_Amount
  11. })
  12. .GroupBy(x => new
  13. {
  14. x.AssemblyName,
  15. x.FinancialYear,
  16. x.TotalExpenditure
  17. })
  18. .Select(g => new
  19. {
  20. g.Key.AssemblyName,
  21. g.Key.FinancialYear,
  22. g.Key.TotalExpenditure,
  23. TotalACBill = g.Sum(x => x.AC_Bill_Amount)
  24. });

答案2

得分: 0

以下是翻译好的部分:

  1. 在我看来,你想要这个:
  2. from fa in fund_allotment
  3. join mab in mla_ac_bill
  4. on new { fa.assembly_name, fa.financial_year }
  5. equals new { mab.assembly_name, mab.financial_year }
  6. group mab.ac_bill_amount
  7. by new { fa.assembly_name, fa.financial_year, fa.total_expenditure }
  8. into g
  9. select new
  10. {
  11. g.Key.assembly_name,
  12. g.Key.financial_year,
  13. g.Key.total_expenditure,
  14. TOTAL_AC_BILL = g.Sum()
  15. };
英文:

It seems to me that you want this:

  1. from fa in fund_allotment
  2. join mab in mla_ac_bill
  3. on new { fa.assembly_name, fa.financial_year }
  4. equals new { mab.assembly_name, mab.financial_year }
  5. group mab.ac_bill_amount
  6. by new { fa.assembly_name, fa.financial_year, fa.total_expenditure }
  7. into g
  8. select new
  9. {
  10. g.Key.assembly_name,
  11. g.Key.financial_year,
  12. g.Key.total_expenditure,
  13. TOTAL_AC_BILL = g.Sum()
  14. };

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:

确定