count(*) - count(onhand) : COUNT « Aggregate Functions « Oracle PL/SQL Tutorial






SQL>
SQL> create table product(
  2          product_id          integer     primary key
  3          ,price                  number(7,2)
  4          ,description            varchar2(75)
  5          ,onhand                 number(5,0)
  6          ,reorder                number(5,0)
  7          ,supplier_no            integer
  8  );

Table created.

SQL> -- product Table Inserts:
SQL> insert into product(product_id, price, description, onhand, reorder)values (1,2.50,'Happy Birthday',100,20);

1 row created.

SQL> insert into product(product_id, price, description, onhand, reorder)values (2,23.00,'Happy Birthday',null,null);

1 row created.

SQL> insert into product(product_id, price, description, onhand, reorder)values (3,null,'Happy New Year',null,null);

1 row created.

SQL> insert into product(product_id, price, description, onhand, reorder)values (4,1.50,'Happy New Year',50,10);

1 row created.

SQL>
SQL>
SQL> select count(*) - count(onhand) from product;

COUNT(*)-COUNT(ONHAND)
----------------------
                     2

1 row selected.

SQL>
SQL> drop table product;

Table dropped.








12.3.COUNT
12.3.1.COUNT(x) gets the number of rows returned by a query.
12.3.2.Passes ROWID to COUNT() and gets the number of rows
12.3.3.COUNT() with null
12.3.4.Using an aggregate with the GROUP BY clause to count by city
12.3.5.COUNT(1) from a table
12.3.6.Count column with table alias
12.3.7.Count distinct column value
12.3.8.Compare the difference between count(*) and count(distinct course)
12.3.9.Count employees in the same department
12.3.10.JOIN with AND and aggregate function
12.3.11.count(*) - count(onhand)
12.3.12.count(*) vs count(column name)
12.3.13.Count all employees by even/odd employee id
12.3.14.Count date field value, and calculation