10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

System-defined FunctionsFor example, the following statement selects rows from a table of politicalcandidates, groups the rows by party, and returns each party's name and theaverage funding for the candidates in that party.select party, avg(funding)from candidatesgroup by party;Restrictions on the Use of Aggregate FunctionsThe following restrictions apply to the use of aggregate functions:• You cannot nest aggregate functions.• You can use aggregate functions only in select or having clauses.• If a select or having clause contains an aggregate function, columns notspecified in the aggregate must be specified in the group by clause, forexample:select dept, avg(emp_age)from employeegroup by dept;This select statement specifies two columns, dept and emp_age, but onlyemp_age is referenced by the avg aggregate function. The dept column isspecified in the group by clause.The Ifnull FunctionThe ifnull function enables you to specify a value, other than a null, that isreturned to your application when a null is encountered. The ifnull function isspecified as follows:ifnull(v1,v2)If the value of the first argument is not null, then ifnull returns the value of thefirst argument. If the first argument evaluates to a null, then ifnull returns thesecond argument.For example, the sum, avg, max, and min aggregate functions return a null ifthe argument to the function evaluates to an empty set. To receive a valueinstead of a null when the function evaluates to an empty set, you can use theifnull function, as in this example:ifnull(sum(employee.salary)/25, -1)Ifnull returns the value of the expression “sum(employee.salary)/25” unlessthat expression is null. If that expression is null, the ifnull function returns -1.Language Elements 63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!