Which two statements are true regarding the COUNT function? (Choose two.)
A.
COUNT(*) returns the number of rows including duplicate rows and rows containing NULL
value in any of the columns
B.
COUNT(cust_id) returns the number of rows including rows with duplicate customer IDs and
NULL value in the CUST_ID column
C.
COUNT(DISTINCT inv_amt) returns the number of rows excluding rows containing duplicates
and NULL values in the INV_AMT column
D.
A SELECT statement using COUNT function with a DISTINCT keyword cannot have a WHERE
clause
E.
The COUNT function can be used only for CHAR, VARCHAR2 and NUMBER data types
Explanation:
Using the COUNT Function
The COUNT function has three formats:
COUNT(*)
COUNT(expr)
COUNT(DISTINCT expr)
COUNT(*) returns the number of rows in a table that satisfy the criteria of the SELECT statement,
including duplicate rows and rows containing null values in any of the columns. If a WHERE
clause is included in the SELECT statement, COUNT(*) returns the number of rows that satisfy the
condition in the WHERE clause.
In contrast,
COUNT(expr) returns the number of non-null values that are in the column identified by expr.COUNT(DISTINCT expr) returns the number of unique, non-null values that are in the column
identified by expr.
it’ s about B.I do a test.
SQL> select * from emp order by mgr;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
———- ———- ——— ———- ——— ———- ———- ———-
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
———- ———- ——— ———- ——— ———- ———- ———-
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7839 KING PRESIDENT 17-NOV-81 5000 10
14 rows selected.
SQL> select count(mgr) from emp;
COUNT(MGR)
———-
13
It seems B is correct only if there is any condition on cust_id.
Answer will be A & C
B is wrong. Please check the below example
Select Count(ids)
From (Select Null Ids From Dual
Union All
Select ‘AAA’ Ids From Dual
Union All
Select ‘BBB’ Ids From Dual
Union All
Select Null Ids From Dual
Union All
Select ‘AAA’ Ids From Dual);
This returns 3 as it excludes the Null values.
Answer will be A and C