SQL COUNT() ফাংশন
- Previous Page SQL avg()
- Next Page SQL first()
COUNT() ফাংশন নির্দিষ্ট শর্তমূলক সারানো সংখ্যা ফিরিয়ে দেয়。
SQL COUNT() সংজ্ঞা
SQL COUNT(column_name) সংজ্ঞা
COUNT(column_name) ফাংশন নির্দিষ্ট কোলামের মানের সংখ্যা ফিরিয়ে দেয় (NULL যোগ করা হয় না):
SELECT COUNT(column_name) FROM table_name
SQL COUNT(*) সংজ্ঞা
COUNT(*) ফাংশন টেবিলের রেকর্ডের সংখ্যা ফিরিয়ে দেয়:
SELECT COUNT(*) FROM table_name
SQL COUNT(DISTINCT column_name) সংজ্ঞা
COUNT(DISTINCT column_name) ফাংশন নির্দিষ্ট কোলামের ভিন্ন মানের সংখ্যা ফিরিয়ে দেয়:
SELECT COUNT(DISTINCT column_name) FROM table_name
মন্তব্য:COUNT(DISTINCT) অপরিবর্তনীয় হয় ORACLE এবং Microsoft SQL Server-এর জন্য, কিন্তু Microsoft Access-এ ব্যবহার করা যায় না。
SQL COUNT(column_name) Example
We have the following 'Orders' table:
O_Id | OrderDate | OrderPrice | Customer |
---|---|---|---|
1 | 2008/12/29 | 1000 | Bush |
2 | 2008/11/23 | 1600 | Carter |
3 | 2008/10/05 | 700 | Bush |
4 | 2008/09/28 | 300 | Bush |
5 | 2008/08/06 | 2000 | Adams |
6 | 2008/07/21 | 100 | Carter |
Now, we want to calculate the number of orders for customer 'Carter'.
We use the following SQL statement:
SELECT COUNT(Customer) AS CustomerNilsen FROM Orders WHERE Customer='Carter'
The result of the above SQL statement is 2 because customer Carter has 2 orders:
CustomerNilsen |
---|
2 |
SQL COUNT(*) Example
If we omit the WHERE clause, for example:
SELECT COUNT(*) AS NumberOfOrders FROM Orders
The result set is similar to this:
NumberOfOrders |
---|
6 |
This is the total number of rows in the table.
SQL COUNT(DISTINCT column_name) Example
Now, we want to calculate the number of different customers in the 'Orders' table.
We use the following SQL statement:
SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers FROM Orders
The result set is similar to this:
NumberOfCustomers |
---|
3 |
This is the number of different customers (Bush, Carter, and Adams) in the 'Orders' table.
- Previous Page SQL avg()
- Next Page SQL first()