SQL COUNT WHERE
The SQL Count() function can also be used with the WHERE clause in the SELECT statement.
The Count() with WHERE clause returns only those rows from the table which match with the condition specified in the WHERE clause.
Syntax of SQL Count() Function With WHERE clause
Examples of SQL Count Function with WHERE clause
Example 1: First create a table and then run the count function.
The following CREATE TABLE statement creates the Cars_Details table with five fields:
The following INSERT query inserts the record of cars into the Cars_Details table:
The following SELECT query shows the data of the Cars_Details table:
The following query shows the total value of those cars whose Car_Number is greater than and equal to 7000:
Example 2: The following query creates the College_Student_Details table using the CREATE TABLE statement:
The following SQL queries insert the record of students into the above table using INSERT INTO statement:
Let's see the record of the above table using the following SELECT statement:
The following Count query displays the total number of those students whose Student_Marks is greater than 90: