Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Need help on a continuation of the "how to get the first 10 records with order by" problem
I have the following code, using just one customer as an example but
needing to get 13 "reads" back from each customer in order of most recent
date first. There will not always be 13 reads available and there will
definitely be more reads than 13 in the database.
select prem_code, billed_chg, billed_consump,
to_char(action_date,'MM/DD/YYYY')
from urrshis us,
ubbchst ub, uabopen ua where 13 >= (select count( distinct to_char(action_date,'MM/DD/YYYY')) from urrshis ur where ur.action_date <= us.action_date and prem_code = '1110' and ur.scat_code = us.scat_code)and ua.prem_code = '1110'
and ub.scat_code = ua.scat_code and ub.prem_code = ua.prem_code and ur.prem_code = ub.prem_code
For this particular customer there are exactly 10 records. This gets back what I need when I use a count of 10 or more, however if I use "where 9 >=" then it cuts out the most recent date and so forth on down. What the user wants is to look at the most recent records for all customers. There may be more than 13 read dates but they want only the most recent ones. The number of records coming back will vary for each customer. Is there a way to do this in a select statement without calling functions?
Thanks for any help you can give, I hope I haven't left out anything pertinent... Received on Tue Oct 19 1999 - 15:59:48 CDT
![]() |
![]() |