SQL HAVING Clause

As Where clauses are not used with aggregate functions, so we use the HAVING clause to perform aggregate functions.The HAVING clause is used to restrict the results returned by Group BY Clause.

HAVING Clause Syntax :

The syntax of theHAVING Clause is −

SELECT column-name(s)
FROM table-name
WHERE condition
GROUP BY column-name(s)
HAVING condition
ORDER BY column-name(s);   



HAVING Clause Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary Gender
1 Aarav 28 Udaipur 28000 M
2 Aarushi 25 Mumbai 30000 F
3 Reyansh 28 Chennai 35000 M
4 Aditi 24 Udaipur 50000 F
5 Sai 30 Mumbai 27000 M


Test Case:- The following code is an example, which would fetch the age field from Customer table where the count of similar age is greater than or equal to 2.

SELECT Age
FROM Customer
GROUP BY Age
HAVING COUNT(Age) >= 2;   


The result for the respective sql query is as follows −

Age
28





Visit :


Discussion



* You must be logged in to add comment.

pHqghUme
555

pHqghUme
555

pHqghUme
555

pHqghUme
-1 OR 2+302-302-1=0+0+0+1 --

pHqghUme
-1 OR 3+302-302-1=0+0+0+1 --

pHqghUme
-1 OR 3*2<(0+5+302-302) --

pHqghUme
-1 OR 3*2>(0+5+302-302) --

pHqghUme
-1 OR 2+13-13-1=0+0+0+1

pHqghUme
-1 OR 3+13-13-1=0+0+0+1

pHqghUme
-1 OR 3*2<(0+5+13-13)

pHqghUme
-1 OR 3*2>(0+5+13-13)

pHqghUme
-1' OR 2+919-919-1=0+0+0+1 --

pHqghUme
-1' OR 3+919-919-1=0+0+0+1 --

pHqghUme
-1' OR 3*2<(0+5+919-919) --

pHqghUme
-1' OR 3*2>(0+5+919-919) --

pHqghUme
-1' OR 2+80-80-1=0+0+0+1 or 'uhv8bz4s'='

pHqghUme
-1' OR 3+80-80-1=0+0+0+1 or 'uhv8bz4s'='

pHqghUme
-1' OR 3*2<(0+5+80-80) or 'uhv8bz4s'='

pHqghUme
-1' OR 3*2>(0+5+80-80) or 'uhv8bz4s'='

pHqghUme
-1" OR 2+259-259-1=0+0+0+1 --

pHqghUme
-1" OR 3+259-259-1=0+0+0+1 --

pHqghUme
-1" OR 3*2<(0+5+259-259) --

pHqghUme
-1" OR 3*2>(0+5+259-259) --

pHqghUme
if(now()=sysdate(),sleep(15),0)

pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

pHqghUme
-1; waitfor delay '0:0:15' --

pHqghUme
-1); waitfor delay '0:0:15' --

pHqghUme
1 waitfor delay '0:0:15' --

pHqghUme
7xNgXXmV'; waitfor delay '0:0:15' --

pHqghUme
-5 OR 466=(SELECT 466 FROM PG_SLEEP(15))--

pHqghUme
-5) OR 606=(SELECT 606 FROM PG_SLEEP(15))--

pHqghUme
-1)) OR 467=(SELECT 467 FROM PG_SLEEP(15))--

pHqghUme
149J3bgI' OR 49=(SELECT 49 FROM PG_SLEEP(15))--

pHqghUme
YnPLNFMq') OR 387=(SELECT 387 FROM PG_SLEEP(15))--

pHqghUme
aCCWcdB2')) OR 177=(SELECT 177 FROM PG_SLEEP(15))--

pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

pHqghUme
1'"

pHqghUme

pHqghUme
@@XVEEn

pHqghUme
555

pHqghUme
555

pHqghUme
555