[英]Is there a linq to entities equivalent for the LAG() function in SQL?
I created a query for a Month-Over-Month Sales report using the LAG function in SQL. 我使用SQL中的LAG函数创建了按月销售报表的查询。 I discovered that is not available in linq. 我发现在linq中不可用。 Is there a way to still accomplish this? 有没有办法做到这一点?
LinqTo2Db
supports Window-Functions Lag
and Lead
: LinqTo2Db
支持窗口函数 Lag
和Lead
:
from x in db.Events
let prev = Sql.Ext
.Lag(x.app, Sql.Nulls.None)
.Over()
.OrderBy(x.time)
.ToValue()
where (prev != x.app && prev != null)
select (prev, x.app)
First 8
of all 43 supported funcs (!) 所有43个受支持的功能中的前8
(!)
|-------------|----------------------|
| SQL | Linq2db |
|-------------|----------------------|
| AVG | Sql.Ext.Average() |
| CORR | Sql.Ext.Corr() |
| COUNT | Sql.Ext.Count() |
| COVAR_POP | Sql.Ext.CovarPop() |
| COVAR_SAMP | Sql.Ext.CovarSamp() |
| CUME_DIST | Sql.Ext.CumeDist() |
| DENSE_RANK | Sql.Ext.DenseRank() |
| FIRST_VALUE | Sql.Ext.FirstValue() |
|-------------|----------------------|
Note There is no limitation in window functions usage. 注意窗口函数的使用没有限制。
LINQ To DB
will createSQL
and run query, if function is not supported or some part of function is limited in particularDatabase
- error will be thrown on database side.LINQ To DB
将创建SQL
并运行查询,如果不支持功能或功能的某些部分在特定Database
受到限制-将在数据库端引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.