select sum([CardPrice]) as SurplusValue from [CardPassword] where [IsUses]='0' and createdatetime>='2014-5-24'
EF
from t in
(from t in context.CardPasswords
where
t.IsUses == "0" &&
t.CreateDateTime >= DateTime.Parse("2014-5-24")
select new
{
t.CardPrice,
Dummy = "x"
})
group t by new {t.Dummy}
into g
select new
{
SurplusValue = g.Sum(p => p.CardPrice)
};
注意到上面加了个Dumy,用来强制分组的
本文展示了一个SQL查询,用于计算数据库中未使用的、创建日期大于等于2014年5月24日的卡片的价格总和。通过使用EF框架和LINQ,作者演示了如何从CardPassword表中筛选数据,并对筛选结果进行分组和求和操作。
938

被折叠的 条评论
为什么被折叠?



