Solution 2
1. Count the customers with grades above Bangalore’s average
HAVING GRADE>(SELECT AVG(GRADE)
FROM CUSTOMER WHERE CITY='BANGALORE');
2.Find the name and numbers of all salesman who had more than one customer
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 UNION SELECT S.SALESMAN_ID, S.NAME, 'NO MATCH', S.COMMISSION FROM SALESMAN S WHERE CITY NOT IN (SELECT CITY FROM CUSTOMER) ORDER BY 1 ASC;
4. Create a view that finds the salesman who has the customer with the highest order of a day.
CREATE VIEW V_SALESMAN AS
SELECT O.ORDER_DATE, S.SALESMAN_ID,
S.NAME FROM SALESMAN S,ORDERS O
WHERE S.SALESMAN_ID = O.SALESMAN_ID
AND O.PURCHASE_AMOUNT= (SELECT MAX(PURCHASE_AMOUNT)
FROM ORDERS C WHERE C.ORDER_DATE=O.ORDER_DATE);
5. Demonstrate the DELETE operation by removing salesman with id 1000. All his orders must also be deleted.
DELETE FROM SALESMAN WHERE SALESMAN_ID=1000;
DECLARE
v_row_count NUMBER;
BEGIN
DELETE FROM SALESMAN
WHERE Salesman_id = 1001;
v_row_count := SQL%ROWCOUNT;
DBMS_OUTPUT.PUT_LINE('Number of rows deleted: ' || v_row_count);
END;
/
Comments
Post a Comment