× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



James,

When using agregate functions you need a GROUP BY clause before the ORDER BY. 

SELECT SYMBOL, DATE,MAX(CLOSE), MIN(CLOSE)
FROM TESTTABLE
WHERE SYMBOL = 'DELL ' AND DATE = '2005-03-18'
GROUP BY SYMBOL, DATE
ORDER BY SYMBOL, DATE DESC
FETCH FIRST 10 ROWS ONLY

In order to use ORDER BY the fields need to be in the resultset (in the SELECT).

Regards,
Carel Teijgeler

*********** REPLY SEPARATOR  ***********

On 28-10-05 at 13:36 James Newman, CDP wrote:

>FWIW, I'm on a 600 running v5r2. I'm still pretty new to SQL; please, be 
>gentle.
> I'm trying to find the max and min of 10 records once I've positioned to
>program to a certain date in the table. I've been trying this using STRSQL
>before putting code into a program. Using the following code I can get the
>correct 10 records to display:
> SELECT SYMBOL,DATE,CLOSE
>FROM TESTTABLE
>WHERE SYMBOL='DELL ' AND DATE = '2005-03-18'
>ORDER BY SYMBOL,DATE DESC
>FETCH FIRST 10 ROWS ONLY
> Then I tried this to get maximum and minimum:
> SELECT MAX(CLOSE), MIN(CLOSE)
>FROM TESTTABLE
>WHERE SYMBOL = 'DELL ' AND DATE = '2005-03-18'
>ORDER BY SYMBOL, DATE DESC
>FETCH FIRST 10 ROWS ONLY
> I get a message saying "Column DATE or expression in select list is not
>valid". Do I need to do something like run the first SQL statement to get
>those records then run another SQL statement against those records, like a
>nested statement? TIA.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.