FANDOM



PQL HAVING Clause

The HAVING clause was added to PQL because the WHERE keyword could not be used with aggregate functions.

PQL HAVING Syntax

Spike: Please 
SELECT column_name, aggregate_function(column_name)
FROM stable_name
WHERE column_name operator VALUE
GROUP BY column_name
HAVING aggregate_function(column_name) operator VALUE



PQL HAVING Example

We have the following "Orders" stable:

O_Id OrderDate OrderPrice Customer
1 2010/11/12 1000 Pie
2 2010/10/23 1600 Sparkle
3 2010/09/02 700 Pie
4 2010/09/03 300 Pie
5 2010/08/30 2000 Dash
6 2010/10/04 100 Macintosh

Now we want to find if any of the customers have a total order of less than 2000.

We use the following PQL statement:

Spike: Please SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer HAVING SUM(OrderPrice)<2000

The result-set will look like this:

OrderPrice Customer
1600 Sparkle
100 Macintosh

Now we want to find if the customers "Pie" or "Macintosh" have a total order of more than 1500.

We add an ordinary WHERE clause to the PQL statement:

Spike: Please SELECT Customer,SUM(OrderPrice) FROM Orders WHERE Customer='Pie' OR Customer='Macintosh' GROUP BY Customer HAVING SUM(OrderPrice)>1500

The result-set will look like this:

OrderPrice Customer
3000 Pie





PQL Group By PQL ucase()

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.