**** By arthematic operators

****
-->
-->
-->
-->
-->

Addition : +
Subtration : Multiplication : *
Division : /
Modulus : %

these operations are held in SELECT syntax only.
For Example:
SELECT SALES_AMOUNT,TAX_AMOUNT,TOTAL_AMOUNT,SALES_AMOUNT+TAX_AMOUNT
FROM SALES
we can also use num in sytax with characters along with opeations.
For Example:
SELECT SALES_AMOUNT,TAX_AMOUNT,TOTAL_AMOUNT,SALES_AMOUNT+TAX_AMOUNT
FROM SALES,TOTAL_AMOUNT*10
EXCERSISES:
1.Produce a list of rows showing sales date, product number, order number, sales
amount,
tax amount and a calculated column (sum of sales amount and tax amount) from the
SALES table
Qurey:
SELECT SALES_DATE,PRODUCT_NUMBER,ORDER_NUMBER,SALES_AMOUNT,TAX_AMO
UNT,SALES_AMOUNT+TAX_AMOUNT
FROM SALES
2. Produce a list of rows showing all columns from the SALES table where quantit
y plus 10 is
greater than or equal to 20
Qurey:

SELECT *
FROM SALES,
WHERE QUANTITY+10 >= 20

3. Produce a list of rows showing sales date, product number, order number, sale
s amount,
tax amount and a calculated column (total amount minus 30) from the SALES table
Qurey:
UNT

SELECT SALES_DATE,PRODUCT_NUMBER,ORDER_NUMBER,SALES_AMOUNT,TAX_AMO
FROM SALES
WHERE TOTAL_AMOUNT-30

SORTING OF DATA:
How to sort the data?
Arranging the values either in a assending order or decendiong order
In the same way, in data base also can perform sorting.
The command for sorting data is :
ORDER BY cOLUMN NAMES
Example for above command:
1.In this command, sorting thier data in decending order
SELECT SALES_DATE, SALES_AMOUNT, TAX_AMOUNT, TOTAL_AMOUNT,

then it shows Qurey Result as per the order(ASC /DESC). FROM SALES ORDER BY TAX_AMOUNT. tax amount from the SALES table and sort it by order number in descending order.ORDER_ID.PRODUCT_ID. SELECT ORDER_ID. FROM SALES ORDER BY SALES_AMOUNT. tax amount from the SALES table and sort it by column tax amount in ascending or der.PRODUCT_ID. Note: 1. 3. FROM SALES ORDER BY ORDER_ID DESC.SALES_AMOUNT. sales date. SELECT SALES_DATE. TOTAL_AMOUNT.FROM SALES ORDER BY SALES_DATE DESC. order number. tax amount from the SALES table and sort it by column sales amount and tax amoun t in ascending order.TAX_AMOUNT.In this command. How do we combine data from Two Tables: . product number. sorting thier data in acending order SELECT SALES_DATE.For Dcending order : DESC Acending is a default sorting In this way . Produce a list of rows showing sales date. 2. sale s amount.TAX_AMOUNT. product number.For Acending order : ASC 2. Produce a list of rows showing order number. product number.SALES_DATE.we can perform sorting on the data.TAX_AMOUNT. NULL DATA: When it comes in ASC: NULL data will sort at the bottom. TAX_AMOUNT.SALES_AMOUNT. SALES_AMOUNT. 2. SELECT SALES_DATE. When it comes in DESC: NULL data will sort at the top.ORDER_ID.PRODUCT_ID. Syntax: SELECT * FROM PRODUCT ORDER BY COLUMN NAME NOTE: When column has null value. Produce a list of rows showing sales date. sale s amount.TAX_AMOUNT. FROM SALES ORDER BY SALES_DATE.SALES_AMOUNT. Excersises: 1. order number. sale s amount.

Note: In this type of operator.product_id. UNION ALL EXAMPLE COMMAND : SELECT sales_date.product_id. MINUS EXAMPLE COMMAND : SELECT sales_date.product_id.customer_id FROM sales_history.including all All distinct rows selected by both quries All distinct rows selected by the first query b 1. INTRSECT EXAMPLE COMMAND : SELECT sales_date.customer_id FROM sales_history. Note: Ater using minus command. IMP NOTE: The columns with which you are performing set oprations from both the table should have the same data type Operator Returns UNION ------------------- UNION ALL ------------------duplicates INTERSECT ------------------MINUS ------------------ut not the second. Produce a list of ALL rows showing order number by combining data from SALES and SALES_HISTORY table. 2.product_id. 4.product_id.UNION EXAMPLE COMMAND: SELECT sales_date. all the column values should match in both th e tables.customer_id FROM sales INTRSECT SELECT sales_date.customer_id FROM sales_history. Produce a list of DISTINCT rows from SALES and SALES_HISTORY table using colu mn .1.product_id. 2. result will be taken from first mentioned tab le Excersises 1.SET OPERATORS: With this type of operators. All distinct rows selected by either query All rows selected by either query. SELECT ORDER_ID FROM SALES UNION ALL SELECT ORDER_ID FROM SALES_HISTORY.customer_id FROM sales_history.customer_id FROM sales UNION ALL SELECT sales_date.product_id.customer_id FROM sales MINUS SELECT sales_date.product_id.how to get data from multiple tables and combine t he results. 3.customer_id FROM sales UNION SELECT sales_date.

the sum of values in the group. the avarage values of the group.CUSTOMER_ID.Summary or grouping the data 3. a database can do on a set of rows. 6. 5. Produce a list of rows which are present in SALES table and are not present i n SALES_HISTORY table using column order number. SUM(TOTAL_AMOUNT) FROM SALES Group by with multiple columns: Bussiness Example Syntax: SELECT SALES_DATE. Grouping The Data(GROUP BY) : Aggregate: Aggregate functions returns a single result row based on group of row s. summary: combining a multiple rows into a value which is meaning What kind of summary a data base can do? Here are some functions .g:. SELECT ORDER_ID FROM SALES INTRSECT SELECT ORDER_ID FROM SALES_HISTORY. Produce a list of COMMON rows between SALES and SALES_HISTORY table using col umn order number. 3. SELECT COUNT(*). 3.SUM(TOTAL_AMOUNT) FROM SALES ---. rather than on single rows. SELECT ORDER_ID FROM SALES MINUS SELECT ORDER_ID FROM SALES_HISTORY.order number. 4. SELECT ORDER_ID FROM SALES UNION SELECT ORDER_ID FROM SALES_HISTORY. SELECT SALES_DATE. 4. the last value in the group. the largest value in the group. the first value in the group. 1.PRODUCT_ID.MIN(TOTAL_AMOUNT) FROM SALES Group By Clause: It is a type in which all the types of similar data group merged in a single row . Example Commands for above functions: 1. 7. sELECT COUNT(*). Minimum |---| Maximun |---| Addition|---| Average |---| Count |---| First |---| Last |---| MIN() MAX() SUM() AVG() COUNT() FIRST() LAST() |------| |------| |------| |------| |------| |------| |------| Returns Returns Returns Returns Returns Returns Returns the smallest value.SUM(TOTAL_VOLUME) FROM SALES . SELECT COUNT(*) FROM SALES 2.SUM(TOTAL_AMOUNT). number of rows in the result set. 2. Command Structure: E.

MAX(TOTAL_AMOUNT) FROM SALES GROUP BY SALES_DATE.ORDER_ID. Produce a list which shows total sales volume broken by sales date from SALES table. Exercise 1.PRODUCT_ID HAVVING SUM(TOTAL_AMOUNT)>100.cUSTOMER_ID ORDER BY SALES_DATE.ORDER_ID 4. (Hint: use HAVING clause) SELECT SALES_DATE. MIN(TOTAL_AMOUNT) FROM SALES GROUP BY SALES_DATE HAVING MIN(TOTAL_AMOUNT<100) . Produce a list which shows minimum sales volume broken by sales date from SAL ES table and minimum sales volume is less than 100. SELECT SALES_DATE. SELECT COUNT(*) FROM SALES 2.PRODUCT_ID.WHERE SALES_DATE BETWEEN '01-JAN-15' AND 31-JAN-15' GROUP BY SALES_DATE. SELECT SALES_DATE.CUSTOMER_ID Group by with HAVING clause: Having clause is to consider aggregated expression or summary expression Example Command: SELECT SALES_DATE.PRODUCT_ID.SUM(TOTAL_AMOUNT) FROM SALES WHERE SALES_DATE BETWEEN '01-JAN-15' AND 31-JAN-15' GROUP BY SALES_DATE.PRODUCT_ID. SUM(TOTAL_AMOUNT) FROM SALES GROUP BY SALES_DATE 3. Produce a list which shows maximum sales volume broken by sales date and orde r number from SALES table. Write a query that shows the number of rows in SALES table.