Usage of the count function in Oracle

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.