本文介绍了Linq to SQL相当于SUM GROUP BY SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm having a hard time figuring out how to translate this simple SQL statement to (c#) linq to SQL :

我很难弄清楚如何将这个简单的SQL语句翻译成(c#)linq到SQL: > SELECT table1.vat,SUM(table1.QTY * table2.FLG01 + table1.QTY * table2.FLG04)
FROM table1
table2.key上的内部连接table2 key = table1.key
where '2010-02-01'< = table1.trndate and table1.trndate< ='2010-02-28'
Group by table1.vat

SELECT table1.vat, SUM(table1.QTY * table2.FLG01 + table1.QTY * table2.FLG04)FROM table1inner join table2 on table2.key= table1.keywhere '2010-02-01' <= table1.trndate and table1.trndate <= '2010-02-28'Group by table1.vat

感谢任何帮助

Any help is appreciated

推荐答案

我仍在学习LINQ但这似乎工作

I'm still learning LINQ but this seems to work

var result = from t1 in table1
             from t2 in table2
             where t1.key == t2.key && DateTime.Parse("2010-02-01") <= t1.trndate && t1.trndate <= DateTime.Parse("2010-02-28")
             group new {t1,t2} by t1.vat into g
             select new { vat = g.Key, sum = g.Sum(p => p.t1.QTY*p.t2.FLG01 + p.t1.QTY*p.t2.FLG04)};

我希望能很好地转换为LINQ to SQL,因为我只在对象上试过它。

I hope in translates well to LINQ to SQL because I only tried it on objects.

这篇关于Linq to SQL相当于SUM GROUP BY SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:59