Tuesday, January 16, 2018

How To Use Count() Functionality In Mssql

Hello Friend Today In This Blog I Will Show You How To Use Order By Functionality In Mssql.The COUNT() function returns the number of rows that matches a specified criteria.The SQL COUNT function is used to count the number of rows returned in a SELECT statement.This SQL tutorial explains how to use the SQL COUNT function with syntax, examples, and practice exercises.Not everyone realizes this, but the COUNT function will only count the records where the expression is NOT NULL in COUNT(expression). When the expression is a NULL value, it is not included in the COUNT calculations.SELECT COUNT returns a count of the number of data values.The SQL COUNT function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values.

COUNT() returns 0 if there were no matching rows.The above syntax is the general SQL 2003 ANSI standard syntax. This helps to understand the way SQL COUNT Function is used. But different database vendors may have different ways of applying COUNT function.Bellow, you can see that MySQL, PostgreSQL, and Microsoft SQL Server follows the same syntax as given above. But DB2 and Oracle differs slightly.

Overall, you can use * or ALL or DISTINCT or some expression along with COUNT to count the number of rows w.r.t. some condition or all of the rows, depending up on the arguments you are using along with COUNT function.When the * is used for COUNT(), all records ( rows ) are counted if some content NULL but COUNT(column_name) does not count a record if its field is NULL.SQL COUNT function is the simplest function and very useful in counting the number of records, which are expected to be returned by a SELECT statement.


COUNT() Syntax

SELECT COUNT(column_name)
FROM table_name

WHERE condition;


Here Is An Example Related To Topic

Step 1 :Create database



Create database MNC




Step 2:Create table

Here In This step We Will Create table.

Here In This Step We Required Four Column With Name Uids ,Uname ,Ucountry and Usalary using Parameter bigint,varchar and float.

create table UserDetailinfo
(
Uids bigint,
Uname varchar(50),
Ucountry varchar(200),
Usalary float
);





Step 3 :Create Insert Trigger Functionality

Here In This Step We Will Insert Data Using Insert Command.
Data Will Be Added Manually Using Insert Command.


Insert Into UserDetailinfo values(1,'VIRAJ','INDIA',15000.00)
Insert Into UserDetailinfo values(2,'RAJ','USA',10000.00)
Insert Into UserDetailinfo values(3,'ANIL','UK',12000.00)
Insert Into UserDetailinfo values(4,'SUNIL','CANEDA',9000.00)
Insert Into UserDetailinfo values(5,'SHERYAS','CHINA',11000.00)


select *from UserDetailinfo




Step 4 :Create Count() Functionality 

Here In This Step We Will Count() Data Using Where Clause By Using Count() Functionality .
Data Will Be Added ManuallyUsing Count() Functionality.
Here Data Will Be Counted By Using Count() Functionality By Passing Column Name Ucountry='CHINA'.


SELECT COUNT(Usalary)
FROM UserDetailinfo
WHERE Ucountry='CHINA';


No comments:

Post a Comment