View Single Post

   
  #1 (permalink)  
Old 02-28-2008, 07:13 PM
Jason
 
Posts: n/a
Default Filtering and Aggregate functions

I have a complex statement that is used in a SELECT statement. After
all my calculations I need to do an additional filter on the results.
Can I use an alias anywhere or is the AS clause just for column
display purposes?

Instead of:

SELECT column1,
column2,
some_complex_statement_using_SUM_AVG_and_a_few_CAS E_statements
AS Total
FROM table_name
HAVING
some_complex_statement_using_SUM_AVG_and_a_few_CAS E_statements
> 1


Can I have:

SELECT column1,
column2,
some_complex_statement_using_SUM_AVG_and_a_few_CAS E_statements
AS Total
FROM table_name
HAVING
Total > 1

As I understand it, the HAVING clause is used for filtering AFTER
aggregate functions are calculated so the alias SHOULD be available.
Reply With Quote