Dino Geek, try to help you

How to use HAVING clause in MariaDB?


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.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use