Tuesday, 15 November 2011

SQL Count

The COUNT() function returns the number of rows that matches a specified criteria.

The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:


Syntax 


SELECT COUNT(column_name) FROM table_name


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 : 1

SELECT count(*)  as NoofRecord FROM Custmast

Output :

NoofRecord
         6


Example : 2

SELECT count(Custname)  as NoofRecord FROM Custmast

Output : 

NoofRecord
       6


Example : 2

SELECT count(Distinct Custname)  as NoofRecord FROM Custmast

Output : 

NoofRecord
        5

    * Distinct Same name  or  Dublicate Record Not Allowd ( custname --> kodee two time appear in the table)




No comments:

Post a Comment


”Back