The HAVING clause is used to select data records based on a specified condition. You can also apply ZCQL functions in the query using this clause. The HAVING clause can only be used with SELECT queries.

The syntax for using the HAVING clause is shown below:

SELECT column_name FROM base_table_name GROUP BY column_name HAVING column_name OPERATOR condition

Operators Supported by the HAVING Clause

You can use the following operators in the HAVING conditions in ZCQL SELECT queries:

Operators Description
= Equal to
IS TRUE if the operand is the same as the value
IS NULL TRUE if the operand is a null value
IS NOT NULL TRUE if the operand is not a null value
=! Not equal to
LIKE TRUE if the operand matches a pattern
NOT LIKE TRUE if the operand does not match a pattern
BETWEEN TRUE if the operand value is between the start and end values
IN TRUE if the operand is equal to a list of expressions
NOT IN TRUE if the operand is not equal to a list of expressions
> Greater than
>= Greater than or equal to
< Lesser than
<= Lesser than or equal to

ZCQL Functions with HAVING Clause

ZCQL functions like SUM(), COUNT(), AVG(), etc., can be used with the HAVING clause in a SELECT query.

Example Database:

The employee details of Zylker Technologies are being maintained in the Data Store in the Zylker_Employee_DB table. The table contains the following columns and rows:

ID Name Department Salary
ZT-001 Amelia Burrows Product Management 15000
ZT-2001 Bruce Wayne Sr. Management 85000
ZT-239 Clark Kane Media Relations 85000
ZT-4289 Michelle Mascarenhas Finance 89000

Lets, use the AVG() ZCQL function, with the HAVING clause in an example SELECT query.

SELECT Name, Department, Salary FROM Zylker_Employee_DB GROUP BY Department HAVING AVG(Salary) > 50000

Zylker_Employee_DB.Salary Zylker_Employee_DB.Department Zylker_Employee_DB.Name
85000 Sr. Management Bruce Wayne
89000 Finance Michelle Mascarenhas
Note: This functionality is only available in ZCQL V2. Catalyst will end support for ZCQL V1 on Feb 29th, 2024. We recommend you migrate your existing codebase to ZCQL V2 to utilize ZCQL to it's fullest potential.

Last Updated 2023-09-05 20:06:31 +0530 +0530