The HAVING clause in MariaDB is used with the GROUP BY clause in a SELECT statement to filter the results of a query based on a condition applied to the result of an aggregation function, such as COUNT, AVG, MAX, MIN, or SUM.
Here’s a basic example:
```
SELECT column1, AGGREGATE_FUNCTION(column2)
FROM table
GROUP BY column1
HAVING AGGREGATE_FUNCTION(column2) condition value;
```
For example, suppose you have a “sales” table with “sale_date”, “salesperson_id”, and “amount” columns, and you want to find the salespeople who have sold more than $1000 in total:
```
SELECT salesperson_id, SUM AS total_sales
FROM sales
GROUP BY salesperson_id
HAVING total_sales > 1000;
```
In this example, the GROUP BY clause groups the sales figures by salesperson. The HAVING clause then filters out the groups where the sum of sales (‘total\_sales’) is not more than $1000. So the result would be a list of salesperson IDs and their total sales for those who have sold more than $1000.
It’s important to note that HAVING clause can not be used without GROUP BY clause or an aggregation function.