Advertisement
hgr24

Untitled

Mar 30th, 2022
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.98 KB | None | 0 0
  1. SELECT GRADE, COUNT (DISTINCT CUSTOMER_ID) AS NO_OF_CUSTOMER
  2. FROM CUSTOMER
  3. GROUP BY GRADE
  4. HAVING GRADE > (SELECT AVG(GRADE)
  5.  FROM CUSTOMER
  6.  WHERE CITY='BANGALORE');
  7.  
  8.  
  9. SELECT SALESMAN_ID, NAME
  10.  FROM SALESMAN S
  11.  WHERE ((SELECT COUNT (*)
  12.  FROM CUSTOMER
  13.  WHERE SALESMAN_ID=S.SALESMAN_ID)>1);
  14.  
  15.  
  16. SELECT S.SALESMAN_ID, S.CITY
  17. FROM SALESMAN S
  18. WHERE EXISTS (SELECT *
  19.  FROM CUSTOMER
  20.  WHERE S.CITY=CITY AND
  21.  S.SALESMAN_ID=SALESMAN_ID)
  22.  UNION
  23. SELECT SALESMAN_ID,'NO MATCH OF CITIES'
  24. FROM SALESMAN S
  25. WHERE NOT EXISTS (SELECT *
  26.  FROM CUSTOMER
  27.  WHERE S.CITY=CITY AND
  28.  S.SALESMAN_ID=SALESMAN_ID);
  29.  
  30.  
  31. CREATE VIEW BB AS
  32. SELECT DISTINCT S.SALESMAN_ID,S.ORD_DATE
  33. FROM ORDERS S
  34. WHERE (SELECT SUM(PURCHASE_AMT)
  35.  FROM ORDERS
  36.  WHERE SALESMAN_ID=S.SALESMAN_ID ORD_DATE=S.ORD_DATE )AND
  37. CUSTOMER_ID=S.CUSTOMER_ID AND
  38.  =(SELECT MAX(SUM(PURCHASE_AMT))
  39.  FROM ORDERS S1
  40.  WHERE S1.ORD_DATE=S.ORD_DATE
  41.  GROUP BY S1.ORD_DATE,S1.SALESMAN_ID);
  42.  
  43.  
  44. DELETE FROM SALESMAN
  45.  WHERE SALESMAN_ID=1000;
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement