HAVING Clause
Introduction
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:
copySELECT 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.
copySELECT 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 |
-
This functionality is only available in ZCQL V2.
-
From December 01st, 2024, all your current projects in all your Orgs present in the Development Environment will be automatically mapped to ZCQL V2 Parser.
-
From April 01st, 2025, all the projects present in all Orgs that have already been mapped to ZCQL V2 Parser in Development Environment will be automatically mapped to ZCQL V2 Parser in the Production Environment, if and when production is enabled for the project.
Last Updated 2024-09-03 16:31:06 +0530 +0530
Yes
No
Send your feedback to us