Sav*_*dis 4 sql group-by sum linq-to-sql
我很难弄清楚如何将这个简单的SQL语句转换为(c#)linq to SQL:
SELECT table1.vat, SUM(table1.QTY * table2.FLG01 + table1.QTY * table2.FLG04)
FROM table1
inner join table2 on table2.key= table1.key
where '2010-02-01' <= table1.trndate and table1.trndate <= '2010-02-28'
Group by table1.vat
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏
我还在学习LINQ,但这似乎有用
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)};
Run Code Online (Sandbox Code Playgroud)
我希望能很好地转换为LINQ to SQL,因为我只在对象上尝试过它.
| 归档时间: |
|
| 查看次数: |
8224 次 |
| 最近记录: |