Tuesday, 15 November 2011

SQL Having

 The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

Syntax 


SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value 

The "custmast"  Then

custcode
custname
city
qty
rate
1
Siva
Srivilliputtur
50
70
2
Bala
Sivakasi
30
56
3
Kanna
Madurai
100
200
4
Vijay
Chennai
30
30
5
Kodee
Sandnes
60
80
5
Kodee
Srivilliputtur
60
30


Example :



SELECT CustName,SUM(Qty) FROM custmast
GROUP BY CustName
HAVING SUM(Qty)>110



Output :

custname
qty
Kodee
120


No comments:

Post a Comment


”Back