Suppose that we need use SQL sentence to sum up the prices of invoices grouping by Product,
and display the result under condition that sum is less than 777.
We can use general SQL HAVING Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;
Then I can use the following SQL statement:
SELECT Product, SUM(InvoicePrice)
FROM Invoices
GROUP BY Product
HAVING SUM(InvoicePrice) < 777;
No comments:
Post a Comment