Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread MAX and MIN in an Expression
Mon, Feb 24 2014 12:03 PMPermanent Link

jframe

I want to do something like this:

SELECT WSN, MAX(BASE) - MIN(TOP)FROM PERFS GROUP BY WSN

But I keep getting an error stating "Aggregate functions cannot be used within an expression"

Any thoughts?
Mon, Feb 24 2014 6:08 PMPermanent Link

John Easley

You might have to do this in two swoops..as the error indicates, you cannot use aggregate functions within expressions..

SELECT WSN MAX(BASE) as MaxBase, MIN(TOP) as MinTop INTO memory FirstPass FROM PERFS GROUP BY WSN
;
SELECT (MaxBase - MinTop) as MyCalc FROM memory FirstPass

Note, you may need to use memory\Firstpass depending on your version of DBISAM.

John

jframe wrote:

I want to do something like this:

SELECT WSN, MAX(BASE) - MIN(TOP)FROM PERFS GROUP BY WSN

But I keep getting an error stating "Aggregate functions cannot be used within an expression"

Any thoughts?
Wed, Feb 26 2014 11:32 AMPermanent Link

jframe

This works. Thanks!

John Easley wrote:

You might have to do this in two swoops..as the error indicates, you cannot use aggregate functions within expressions..

SELECT WSN MAX(BASE) as MaxBase, MIN(TOP) as MinTop INTO memory FirstPass FROM PERFS GROUP BY WSN
;
SELECT (MaxBase - MinTop) as MyCalc FROM memory FirstPass

Note, you may need to use memory\Firstpass depending on your version of DBISAM.

John

jframe wrote:

I want to do something like this:

SELECT WSN, MAX(BASE) - MIN(TOP)FROM PERFS GROUP BY WSN

But I keep getting an error stating "Aggregate functions cannot be used within an expression"

Any thoughts?
Fri, Feb 28 2014 4:53 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< I want to do something like this:

SELECT WSN, MAX(BASE) - MIN(TOP)FROM PERFS GROUP BY WSN

But I keep getting an error stating "Aggregate functions cannot be used
within an expression" >>

Is this DBISAM 4.x, or earlier ?  You should be able to use aggregate
functions in expressions in later 4.x versions.

Tim Young
Elevate Software
www.elevatesoft.com
Image