Visit:: Join Telegram To Get Instant Updates: Contact: MAIL: Instagram: Instagram
Visit:: Join Telegram To Get Instant Updates: Contact: MAIL: Instagram: Instagram
io
INSTAGRAM: www.instagram.com/hemanthraj_hemu/
INSTAGRAM: www.instagram.com/futurevisionbie/
1|Page https://hemanthrajhemu.github.io
----------------------------------------------------------------------------------------------
Consider the following schema for Order Database:
https://hemanthrajhemu.github.io
2|Page https://hemanthrajhemu.github.io
----------------------------------------------------------------------------------------------
SCHEMA DIAGRAM:
--------------------------------------------------------------------------------------------------------------------------
https://hemanthrajhemu.github.io
3|Page https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
(Note Username is the system by default & Password is the passkey you entered
in the installation)
Step 4: Now click on SQL->SQL Commands. This is the place where we execute
the SQL Commands.
Step 5: you are in SQL Command Now you can Create table, create view, Run
Queries here & lot more.
https://hemanthrajhemu.github.io
4|Page https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
Create Table: (Follow the Schema Diagram in Creating the Data Base)
-------------------------------------------------------------------------------------------------------
1. Create Table for SALESMAN
NOW RUN.
NOW RUN.
-------------------------------------------------------------------------------------------------------
https://hemanthrajhemu.github.io
5|Page https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
TABLE DESCRIPTION
-------------------------------------------------------------------------------------------------------
1. DESC SALESMAN;
2. DESC CUSTOMER;
https://hemanthrajhemu.github.io
6|Page https://hemanthrajhemu.github.io
3. DESC ORDERS;
https://hemanthrajhemu.github.io
7|Page https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
INSERTION OF VALUES TO TABLE
-------------------------------------------------------------------------------------------------------
1. VALUES INTO SALESMAN;
INSERT INTO SALESMAN
VALUES(<SALESMAN_ID>,<NAME>,<CITY>,<COMMISSION>);
INSERT INTO SALESMAN VALUES(1001,’ABDUL’,’BANGLORE’,20);
INSERT INTO SALESMAN VALUES(1002,'PUNITH','BANGLORE',12);
INSERT INTO SALESMAN VALUES(1003,'HARSH','MANGLORE',07);
INSERT INTO SALESMAN VALUES(1004,'HARSHITH','DELHI',26);
INSERT INTO SALESMAN VALUES(1005,'LEELA','BANGLORE',18);
https://hemanthrajhemu.github.io
8|Page https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
https://hemanthrajhemu.github.io
9|Page https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
RETRIEVAL OF INSERTED VALUES
-------------------------------------------------------------------------------------------------------
1. SALESMAN:
SELECT * FROM SALESMAN;
2. CUSTOMER:
SELECT * FROM CUSTOMER;
https://hemanthrajhemu.github.io
10 | P a g e https://hemanthrajhemu.github.io
3. ORDERS:
SELECT * FROM ORDERS;
-------------------------------------------------------------------------------------------------------
https://hemanthrajhemu.github.io
11 | P a g e https://hemanthrajhemu.github.io
-------------------------------------------------------------------------------------------------------
QUERIES
-------------------------------------------------------------------------------------------------------
1. Count the customers with grades above Bangalore’s average.
SELECT GRADE,COUNT(DISTINCT CUSTOMER_ID) FROM CUSTOMER GROUP
BY GRADE HAVING GRADE > (SELECT AVG(GRADE) FROM CUSTOMER
WHERE CITY='BANGLORE');
2. Find the name and numbers of all salesman who had more than one
customer
SELECT SALESMAN_ID, NAME FROM SALESMAN S WHERE 1<(SELECT
COUNT(*) FROM CUSTOMER WHERE SALESMAN_ID=S.SALESMAN_ID);
https://hemanthrajhemu.github.io
12 | P a g e https://hemanthrajhemu.github.io
3. List all the salesman and indicate those who have and don’t have customers
in their cities (Use UNION operation.)
SELECT S.SALESMAN_ID, S.NAME, C.CUST_NAME, S.COMMISSION FROM
SALESMAN S, CUSTOMER C WHERE S.CITY=C.CITY AND
S.SALESMAN_ID=C.SALESMAN_ID
UNION
SELECT SALESMAN_ID, NAME, 'NO MATCH' ,COMMISSION FROM SALESMAN
WHERE NOT CITY = ANY (SELECT CITY FROM CUSTOMER) ORDER BY 2
DESC;
https://hemanthrajhemu.github.io
13 | P a g e https://hemanthrajhemu.github.io
4. Create a view that finds the salesman who has the customer with the
highest order of a day.
CREATE VIEW V_HIGH_ORDER AS SELECT O.ORD_DATE, S.SALESMAN_ID,
S.NAME FROM SALESMAN S, ORDERS O WHERE
S.SALESMAN_ID=O.SALESMAN_ID AND O.PURCHASED_AMT=(SELECT
MAX(PURCHASED_AMT) FROM ORDERS O1 WHERE
O1.ORD_DATE=O.ORD_DATE);
https://hemanthrajhemu.github.io
14 | P a g e https://hemanthrajhemu.github.io
SELECT S.SALESMAN_ID,S.NAME,O.ORD_NO,O.PURCHASED_AMT
FROM SALESMAN S, CUSTOMER C, ORDERS O
WHERE S.SALESMAN_ID=C.SALESMAN_ID AND
C.CUSTOMER_ID=O.CUSTOMER_ID;
-------------------------------------------------------------------------------------------------------
THE END
-------------------------------------------------------------------------------------------------------
https://hemanthrajhemu.github.io