Left Join,Group By和Sum,其中不存在相关记录

时间:2010-12-09 14:42:20

标签: sql vb.net linq

我正在努力完成以下任务:

SELECT Table1.prod_code, SUM(Table1.prod_bal) AS TotalProdBalance
FROM Table1
LEFT OUTER JOIN Table2 ON Table1.prod_code = Table2.prod_code
WHERE Table2.prod_code IS NULL
GROUP BY Table1.prod_code
HAVING (SUM(Table1.prod_bal) <> 0)

有人可以帮我用VB.net语法将其翻译成Linq吗?

1 个答案:

答案 0 :(得分:0)

检查一下..

Dim query = (From rs1 in Table1
   Join rs2 In Table2 On rs1.prod_code Equals rs2.prod_code
   Group by record.prod_code Into TotalProdBalance = sum(rs1.prod_bal)
   Where rs2.prod_code Equals Null and TotalProdBalance <> 0
   Select rs1.prod_code, TotalProdBalance )