如何为以下Tsql编写
Linq-to-sql语句?
select count(*),sum(Amount),avg(Amount),min(Amount),max(Amount) from TableName
解决方法
HACK ALERT,但它的工作原理.尝试按照所有共享条件对记录进行分组:
var result = from g in db.Employees group g by g.Id.GetType() == typeof(int) into gg select new { Count = gg.Count(),Sum = gg.Sum(x => x.Salary) };
SELECT COUNT(*) AS [Count],SUM([t1].[Salary]) AS [Sum] FROM ( SELECT 1 AS [value],[t0].[Salary] FROM [dbo].[Employee] AS [t0] ) AS [t1] GROUP BY [t1].[value]
有一个子查询涉及,但嘿!这只是一次db旅行