Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operators: SQL supports various arithmetic, logical, character, and relational r operators. Arithmetic Operators: Arithmetic operators in SQL will return.

Similar presentations


Presentation on theme: "Operators: SQL supports various arithmetic, logical, character, and relational r operators. Arithmetic Operators: Arithmetic operators in SQL will return."— Presentation transcript:

1 Operators: SQL supports various arithmetic, logical, character, and relational r operators. Arithmetic Operators: Arithmetic operators in SQL will return numeric values. OperatorsFunctionExample +AddUpdate set emp basic = basic + 500; -SubtractUpdate set emp basic = basic - 500; *MultiplyUpdate set emp basic = basic + basic * 5/100; /DivideUpdate set emp basic = basic + basic * 5/100;

2 Logical Operators: Logical operators in SQL will return either true or false value. OperatorsFunctionExample ANDCheck two conditions are true Select * from emp where basic >= AND basic <= 20000; ORCheck any of the two conditions are true Select * from emp where basic >= OR dept = ‘Sales’; NOTReversed the result of logical expression Select * from emp where NOT(basic >= OR dept = ‘Sales’);

3 Character Operators: Character operators are used to manipulate character strings. OperatorsFunctionExample ||Concatenates character strings Select ‘Name is ‘ || ename from emp; Output: Name is Kumar Name is Umar Name is Vino Name is Raj

4 Comparison Operators: Comparison operators in SQL will compare two quantity OperatorsMeaning/Function =Equal to !=, <>Not equal to >Greater than >=Greater than or equal to

5 OperatorsMeaning/Function INEqual to any member of a given set NOT INNot equal to any member of a given set BETWEENIn between two values NOT BETWEENNot in between two values EXISTSTrue if sub query returns at least one row ANYCompares a value to each list of value (must be prefaced with =,!=,,>=) ALLCompares a value to every list of value (must be prefaced with =,!=,,>=)

6 Example: 1)To find the employees who are clerks, manager or assistant manager. select * from emp where post in (‘Clerk’,’Manager’,’Asst.Manager’); or select * from emp where post = ‘Clerk’ or post = ‘Manager’ or post = ‘Asst.Manager ’ 2) To find the employees who are not clerks, manager or assistant manager. select * from emp where post not in (‘Clerk’,’Manager’,’Asst.Manager’); 3) To find the employees whose salary lies in between and select * from emp where basic between and 20000; or Select * from emp where basic >= AND basic <= 20000; 4) To find the employees whose salary not lies in between and select * from emp where basic not between and 20000;

7 LIKE Operator: (Matching a character pattern) When one does not know the exact value for the search conditions and wishes to use a replaceable parameter a LIKE operator can be used. The replaceable parameters used are shown bellow. SymbolRepresents %Any sequence or more characters _Any single character Example: 1) To list employees whose names begin with ‘U’ select * from emp where ename like ‘U%’ ; 2) To list employees who name start with ‘Kum’ and ends with ‘r’; select * from emp where ename like ‘Kum_r’;

8 Aggregate Functions (Group Functions) Aggregate functions are statistical functions such as MIN,MAX,SUM,AVG,COUNT,STDDEV,VARIANCE and etc. Aggregate functions return results based on groups of rows rather than on single rows. Aggregate function accepts two options, DISTINCT – It causes a group function to consider only distinct values of the argument expression. exp : the DISTINCT average of 1,1,1, 3 is 2 ALL – It causes a group function to consider all values including all duplicates. exp : the ALL average of 1,1,1, 3 is 1.5 Note: if neither option is specified, the default is ALL 1. AVG - returns average value of n. Syntax: AVG( [ DISDINCT | ALL ] n) Example: SELECT AVG (basic) FROM emp; Output: AVG(basic)

9 EnoEnameDeptpostbasic 111KumarSalesManager UmarPurchaseAccountant VinoSalesClerk RajMarketingManager6000

10 2. MAX - returns maximum value of n. Syntax: MAX( [ DISDINCT | ALL ] n) Example: SELECT MAX (basic) FROM emp; Output: MAX(basic) MIN - returns minimum value of n. Syntax: MIN( [ DISDINCT | ALL ] n) Example: SELECT MIN (basic) FROM emp; Output: MIN(basic)

11 4.SUM - returns the sum of values of n. Syntax: SUM( [ DISDINCT | ALL ] n) Example: SELECT SUM (basic) FROM emp; Output: SUM(basic)

12 5.COUNT - returns the number of rows in a query. If we use asterisk(*) this function returns all rows including duplicates and nulls. Syntax: COUNT(* | [ DISTINCT | ALL ] n ) Example: SELECT COUNT (*) FROM emp; Output: COUNT(*) Example: SELECT COUNT (DISTINCT basic) FROM emp; Output: COUNT(basic) STDDEV - returns standard deviation of n Syntax: STDDEV ( [ DISTINCT | ALL] n) 7.VARIANCE - returns variance of n Syntax: VARIANCE ( [ DISTINCT | ALL ] n)


Download ppt "Operators: SQL supports various arithmetic, logical, character, and relational r operators. Arithmetic Operators: Arithmetic operators in SQL will return."

Similar presentations


Ads by Google