o**k 发帖数: 5 | 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 | s*****c 发帖数: 36 | 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 | s*****c 发帖数: 36 | 3 ~~optimize for 5 rows -- sorry, should be this |
|