SQL Count
COUNT is a SQL aggregate function that counts the number of rows matching a specified condition. It returns a value that represents the count of rows that meet the specified condition.
The basic syntax of the COUNT function:
SELECT COUNT(column_name)FROM table_name WHERE condition;
This statement returns the number of rows with a non-null value in column_name that matches the condition. If you want to count all rows in a table, you can use the * as follows.
SELECT COUNT(*) FROM table_name;
The COUNT function can be useful to determine the number of clients in a database, count the number of orders placed for a certain product, or find the number of analysts in a certain department. You can also use it to find duplicates and null values.
In combination with the GROUP BY clause COUNT SQL returns a separate count for each group rather than a single count for the entire table.
For example, you can count the number of shows per genre on the tv_show table:
SELECT genre, COUNT(*)
FROM tv_show
GROUP BY genre;
Instead of retrieving all the rows in the table and then counting them, you can use a WHERE clause to filter the data first and then count only the rows that match the specified criteria.
SELECT genre, COUNT(*)
FROM tv_show
WHERE YEAR_LAUNCH < 2000
GROUP BY genre;
Counting in Coginiti
Coginiti allows you to apply the aggregation functionality to any column by dragging and dropping the values you want to count. Here’s an example of how you can count rows in Coginiti Grid:
- Open the Grid View
- Click “Columns’”
- Drag and drop the values you want to count.
Note that when you drop a column to “Values,” it will come with the last aggregation function you used. Click on it to change and scroll to find the count option.