Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Newbie select question
Thu, Sep 27 2007 1:11 PMPermanent Link

Kai

I need to find all donors from a donations table who have donated more than amount (x) in
total.

If I could use donsum in the where clause as show below, I'd be happy.

But since I cannot, how do I achieve what I need?

TIA
Kai

select donorid, donorname, donoraddress1, donoraddress2, sum(donationamount) as donsum
from donations where donsum > 100 group by donorid order  by donsum
Thu, Sep 27 2007 4:15 PMPermanent Link

"Jeff Cook"
Kia Orans Kai

You need the "HAVING" Clause ...

HAVING Clause

The HAVING clause specifies filtering conditions for a SELECT
statement. The syntax is as follows:

HAVING predicates

Use a HAVING clause to limit the rows retrieved by a SELECT statement
to a subset of rows where aggregated column values meet the specified
criteria. A HAVING clause can only be used in a SELECT statement when:

..   The statement also has a GROUP BY clause.
..   One or more columns are the subjects of aggregate functions.

The value for a HAVING clause is one or more logical expressions, or
predicates, that evaluate to true or false for each aggregate row
retrieved from the table. Only those rows where the predicates evaluate
to true are retrieved by a SELECT statement. For example, the SELECT
statement below retrieves all rows where the total sales for individual
companies exceed $1,000:

SELECT Company, SUM(sales) AS TOTALSALES
FROM Sales1998
GROUP BY Company
HAVING (SUM(sales) >= 1000)
ORDER BY Company


--
Jeff Cook
Aspect Systems Ltd
www.aspect.co.nz
+
Joan and Jeff Cook
The Cooks Oasis
www.cookislandsoasis.com
Image