Usage of the count function in Oracle
Count is used to count the number of records in the query results.
Example Table t_test
Name |
Gender |
Age |
Salary |
Zhang San |
Male |
23 |
2000 |
Li Si |
Female |
34 |
|
Wang Wu |
Male |
25 |
1300 |
① Simple application
Query: Select count (*) from t_test;
Result: 3
Explanation: The above query will return the number of records in the t_test table.
② Applications with where conditions
Query: Select count (*) from t_test where gender = 'male'
Result: 2
Explanation: The above query will return the number of records with the gender field "male" in Table t_test.
③ Application of counting a field
Query: Select count (salary) from t_test
Result: 2
Explanation: The above query will return the number of records in the salary column in The t_test table. If the salary of a record is blank, the result is not counted.
④ Application with distinct
Query: Select count (distint gender) from t_test
Result: 2
Explanation: The preceding query returns the number of records of selectdistinct gender from t_test results.