Skip to main content

Aggregate And Numeric Functions.

                  Aggregate And Numeric Functions



SQL has many built-in functions for performing processing on string or numeric data.

AGGREGATEE FUNCTIONS:-

   ➧Average function:Returns average value of 'n', ignoring null values.
        Example: SELECT AVG(sell_price) from product;

    ➧COUNT :Counts rows in a specified table or view.
       Example:SELECT  COUNT(*) FROM products;

    ➧MIN :Gets the minimum value in a set of values.
        Example:SELECT MIN(unitsinstock) FROM products;

    ➧MAX :Gets the maximum value in a set of values.
       Example:SELECT  MAX(unitsinstock)FROM  products;

    ➧
SUM :Calculates the sum of values
      Example:SELECT SUM(bal_due) from client_master;
       

NUMERIC FUNCTIONS:-

ABS(number)

Returns the absolute positive value of an expression.
Syntax:

ABS(expression)
Example:
SELECT ABS(-1.0), ABS(0.0), ABS(1.0)
Output:
1.0   .0   1.0

CEIL(number)

Returns the smallest integer greater than, or equal to, the specified numeric expression.
Syntax:

CEILING(expression)
Example:
SELECT CEILING($223.45), CEILING($-223.45), CEILING($0.0)
Output:
224.00   -223.00   0.00

FLOOR(number)

Returns the largest integer less than, or equal to, the specified numeric expression.
Syntax:

FLOOR(expression)
Example:
SELECT FLOOR($223.45), CEILING($-223.45), CEILING($0.0)
Output:
223.00   -224.00   0.00

MOD(number, divisor)

Returns the remainder of the division from 2 integer values.
Syntax:

MOD(dividend, divisor)
Example:
SELECT MOD(20,3)
Output:
2

POWER(number, power)

Returns the exponential value for the numeric expression.
Syntax:

POWER(number, power)
Example:
SELECT POWER(2.0, 3.0)
Output:
8.0

SIGN(number)

Returns the sign i.e. positive or negative value for the numeric expression. It returns -1 for negative expressions, a value of 0 for zero
Syntax:

SIGN(number)
Example:
SELECT SIGN(4)
Output:
1

ROUND(number, precision)

Returns the numeric value rounded off to the next value specified.
Syntax:

ROUND(number, number of places)
Example:
SELECT ROUND(1.3456, 2)

SQRT(number)
Returns the square root value of the expression.
Syntax:

SQRT(number)
Example:
SELECT SQRT(4.0)
Output:
2.0

TRUNC(number, precision) 
Returns a numeric value that truncate to the specific places
Syntax:

TRUNCATE(number,places)
Example:
SELECT TRUNCATE(1.3456, 2)
Output:
1.34
.

Comments

Popular posts from this blog

DDL Queries

                        DDL(DATA DEFINITION LANGUAGE)             DDL  refers to "Data Definition Language", a subset of SQL statements that change the structure of the database schema in some way, typically by creating, deleting, or modifying schema objects such as databases, tables, and views.    ➤CREATE ➤ALTER ➤DROP ➤TRUNCATE   ➤RENAME ➥ Create Query:- ➧     CREATE TABLE EMP(EMPID NUMBER(5),NAME VARCHAR2(15), SALARY  NUMBER(7,2),EMAIL VARCHAR(20)); ➧    CREATE TABLE DEPT AS SELECT * FROM DEPARTMENTS; "This Query will Create Table when we want to copy the data of any table into new table.Here old table is DEPARTMENTS. ➥ Alter Query :-  ALTER' COMMAND IS USED TO MODIFY TABLE STRUCTURE. ➧     ALTER TABLE EMP MODIFY EMPID NUMBER(10);  "this will change the data type of any attribute in the table." ➧ ALTER TABLE EMP RENAME COLUMN NAME TO FIRST_NAME; ➧  ALTER TABLE EMP DROP COLUMN HIRE_DATE;

Constraints

                                    CONSTRAINTS Constraints is a rule which enforce entry of only valid data in table. Constraints prevent the deletion of a table if there are dependencies. Types of Constraints:-   ➥ PRIMARY KEY= (unique + not null)   ➥ FOREIGN KEY   ➥ NOT NULL   ➥ UNIQUE   ➥ CHECK ➧PRIMARY KEY:- Specifies the column that uniquely identifies a row in the table. The identified columns must be defined as NOT NULL.  ➧FOREIGN KEY:- Specifies that the values in the column must correspond to values in a referenced primary key or unique key column. ➧NOT NULL:- Specifies that this column cannot hold NULL values. ➧UNIQUE:- Specifies that values in the column must be unique. Column can contain NULL value. ➧CHECK:- Specifies Domain for Column values. A CONSTRAINT can be one of the following: * A column-level constraint * A table-level constraint ➮ Primary Key: SQL> CREATE TABLE EMP(ID NUMBER(3) PRIMAR