如何考虑排名的两列来实现RANK()函数?主列没有唯一值。这是查询:
select *, RANK() over (order by score, posteddate desc) as rank from Post
我需要实现没有偏移限制模式的分页,我认为一种排名功能可以。我有一个部分实现,只适用于独特的,使用'>'或者'<&#;关于用于分页的密钥的操作数。
有什么想法吗?我无法在线找到解决方案。
干杯。
根据要求编辑:我正在使用c#。
答案 0 :(得分:0)
我们使用.Skip(pageIndex * pageSize)
和.Take(pageSize)
进行传呼。您只需要确保首先订购了数据。这将全部在服务器上执行。
例如,如果您想要第4页的内容,并且每个页面应包含20个结果:
var pageIndex = 4;
var pageSize = 20;
var pageContent = db.Post
.OrderBy(p => p.score)
.ThenByDescending(p => p.posteddate)
.Skip(pageIndex * pageSize)
.Take(pageSize);
此处生成的SQL会自动添加ROW_NUMBER()
和TOP
。它可以很好地工作到几十万条记录。
答案 1 :(得分:0)
不完全是答案,但我找到了http://use-the-index-luke.com/sql/partial-results/fetch-next-page
中描述的更好的方法 fields: [
{ name: 'id', type: 'int' },
{ name: 'y', type: 'string' },
{ name: 'y', type: 'string' },
{ name: 'z', type: 'string' }
]
});
Ext.define('Book.model.Shops', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'title', type: 'string' },
{ name: 'body', type: 'string' }
],
hasMany: {model: 'Book.model.Cordinate', name: 'coordinate'}
});
var shops = Ext.create('Book.model.Shops', {id: 1, title: 'some title'});
var coordinate = Ext.create('Book.model.Cordinate', {id: 1, y: 'test'});
var lcoordinate = shops.coordinate();
lcoordinate.add(coordinate);
Ext.Msg.alert(shops.get('title'));
Ext.Msg.alert(shops.coordinate().first().get('y'));