我在我的应用程序中使用自定义分页,所以每次我从我的数据库中获取最新的10条记录,并显示在我的应用程序。密集排序与分页和排序
我的问题是
我想获取最新的用户信息。
获取信息时,每个用户有多个行,所以我使用dense_rank函数来分组这些记录。
例如
RRowNo UserID Location CreatedOn 1 Avsih Delhi 06-02-2014 1 Avsih Mumbai 06-02-2014 1 Avsih Kerala 06-02-2014 2 Nimmi UP 06-02-2014 3 Rahul1 Delhi 06-02-2014 4 Rahul2 Mumbai 06-02-2014 5 Rahul3 Kerala 06-02-2014 6 Rahul4 UP 06-02-2014 7 Rahul5 Delhi 06-02-2014 8 Rahul6 Mumbai 06-02-2014 9 Rahul7 Kerala 06-02-2014 10 Rahul8 UP 06-02-2014 11 Rahul9 UP 07-02-2014
考虑我的表名为EMP
我的查询是
select *
from (
select dense_rank() over (order by userid asc) as rowno,
from emp
) as tab
where rowno>='1' and rowno<='10'
order by Createdon desc
Rahul9是我最新的记录(即createdon必须是2014年7月2日) 我希望该记录是最高的。但通过使用该查询我不能获取 所以请帮助如何修改此查询。
请不要比较苹果(数字)和橙子(字符串)。 “1”是一个字符值。 '1'是一个数字。并且请为您正在使用的DBMS添加标签(Postgres,Oracle,...) –