Redian新闻
>
how to write this query, need help !!
avatar
how to write this query, need help !!# Database - 数据库
o*k
1
In DB2 a table have a field called time ,
time is of timestamp datatype.
How to write a query to retrieve lateset
5 time entries?
for example table person have an age field,
create table person(
name varhar(20),
age timestamp
)
find the youngest 5 person.
Thank
avatar
s*c
2
In DB2, you can specify to retrieve the only top n rows
using
"Optimizer for n rows" or "fetch first on rows only" or
both.
As for your example, you can write such a sql:
select name, age
from person
order by age asc
fetch first 5 rows only
or
select name, age
from person
order by age asc
optimizer for 5 rows
avatar
s*c
3
~~optimize for 5 rows -- sorry, should be this
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。