Subject Re: [firebird-support] Select last - How to select latest data
Author Ivan Prenosil
> What is the syntax to select the latest 30 days data and sort it from
> oldest date to most recent date? (please refer message id 26907,
> question about the same, but i need to change it a bit). I have
> tried :
>
> 'SELECT First 30 CLS, VOL, OPN, HIGH, LOW, DATA,symbol FROM DATA
> WHERE STOCK='''+imya+''' order by DATA ACS'
>
> With the statement above i got the first 30 days data sorted from the
> oldest date to the most recent date.
>
> 'SELECT First 30 CLS, VOL, OPN, HIGH, LOW, DATA,symbol FROM DATA
> WHERE STOCK='''+imya+''' order by DATA DESC'
>
> with the statement above i got the last 30 days data BUT sorted from
> the latest date to the oldest date.
>
> Now i want the latest 30 days data SORTED from the oldest date to the
> most recent date.


Method 1:
'SELECT Skip((SELECT COUNT(*) - 30 FROM DATA)) CLS, VOL, OPN, HIGH, LOW, DATA,symbol FROM DATA
WHERE STOCK='''+imya+''' order by DATA ACS'


Method 2 (you need Firebird 2):

'SELECT * FROM (
SELECT First 30 CLS, VOL, OPN, HIGH, LOW, DATA,symbol FROM DATA
WHERE STOCK=xxx ORDER BY DATA DESC )
ORDER BY DATA ASC


Ivan
http://www.volny.cz/iprenosil/interbase/