IT/Oracle

오라클 View, Index

노마드오브 2018. 7. 26. 22:30

SELECT CUSTID, (SELECT ADDRESS 

                FROM CUSTOMER CS 

                WHERE CS.CUSTID = OD.CUSTID) "ADDRESS",

        SUM(OD.SALEPRICE) "TOTAL"

FROM ORDERS OD

GROUP BY OD.CUSTID;


SELECT CS.NAME, S

FROM (SELECT CUSTID, AVG(SALEPRICE) S

        FROM ORDERS

        GROUP BY CUSTID) OD, 

        CUSTOMER CS

WHERE CS.CUSTID=OD.CUSTID;


CREATE VIEW VW_CUSTOMER

AS SELECT *

    FROM CUSTOMER

    WHERE ADDRESS LIKE '%대한민국%';


SELECT * FROM VW_CUSTOMER;


CREATE VIEW HIGHORDERS

AS SELECT ORDERS.BOOKID, BOOK.BOOKNAME, CUSTOMER.NAME, BOOK.PUBLISHER, ORDERS.SALEPRICE

    FROM ORDERS, BOOK, CUSTOMER

    WHERE BOOK.BOOKID = ORDERS.BOOKID

    AND ORDERS.CUSTID = CUSTOMER.CUSTID

    AND ORDERS.SALEPRICE >= 20000;


SELECT BOOKNAME, NAME

FROM HIGHORDERS;


SELECT *

FROM HIGHORDERS;


CREATE OR REPLACE VIEW HIGHORDERS

AS SELECT ORDERS.BOOKID, BOOK.BOOKNAME, CUSTOMER.NAME, BOOK.PUBLISHER

    FROM ORDERS, BOOK, CUSTOMER

    WHERE BOOK.BOOKID = ORDERS.BOOKID

    AND ORDERS.CUSTID = CUSTOMER.CUSTID

    AND ORDERS.SALEPRICE >= 20000;


CREATE INDEX NAME ON CUSTOMER(NAME);

DROP INDEX NAME;