gpt4 book ai didi

林克。按天分组。如何轻松做到这一点?

转载 作者:行者123 更新时间:2023-12-01 13:06:06 24 4
gpt4 key购买 nike

我似乎找不到任何好的引用资料。我在 SQL 中有很多带有日期的数据。所以我想制作一个折线图来显示这些数据随着时间的推移。如果我想在几天内显示它,那么我需要按天分组..但 LOGDATE 是完整日期.. 不是 DAY..

所以我在下面有这个,但 LINQ 不知道 'DayOfYear' 属性是什么......

 var q = from x in dc.ApplicationLogs
let dt = x.LogDate
group x by new { dayofyear = dt.Value.DayOfYear } into g
select new
{
iCount = g.Count(),
strDate = g.Key
};

最佳答案

在 EF 核心中,您可以使用 DateTime.Date获取 DateTime 的日期部分值(value)。

在 EF6 中,您可以使用 DbFunctions.TruncateTime :

to return the given date with the time portion cleared


var q = from x in dc.ApplicationLogs
let dt = x.LogDate.Date
// EF6:let dt = DbFunctions.TruncateTime(x.LogDate)
group x by dt into g
select new
{
iCount = g.Count(),
strDate = g.Key
};

关于林克。按天分组。如何轻松做到这一点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3057383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com