Overview
TheCOUNT() function allows you to retrieve the number of records that match a specific condition. It can be used with any data type supported by Oxla, and the output will be returned as a BIGINT.
The output will indicate the total number of rows in a table, regardless of the input types.
Examples
In this example, we will use an orders table that stores details of the purchase transactions:Case #1: COUNT() with a single expression
The following example will return the number of all orders in the orders table:
Case #2: COUNT() with a GROUP BY clause
This example will combine the COUNT() function and the GROUP BY clause.
- The
GROUP BYclause groups the orders based on the customer’s name. - The
COUNT()function counts the orders for each customer.
Case #3: COUNT() with a HAVING clause
In this example, we combine the COUNT() function and the HAVING clause to apply a specific condition to find customers who have made more than two orders:
- The
GROUP BYclause groups the orders based on the customer’s name. - The
HAVINGclause will filter only customers with more than two order IDs. - The
COUNT()function counts the orders for each customer.