VIEW
-- 원본
SELECT COUNT(*) AS num_shipped, MAX(ship_date), title
FROM shipments
JOIN editions USING (isbn)
NATURAL JOIN books AS b (book_id)
GROUP BY b.title
ORDER BY num_shipped DESC;
-- view 만들기
CREATE VIEW recent_shipments
AS SELECT count(*) AS num_shipped, MAX(ship_date), title
FROM shipments
JOIN editions USING (isbn)
NATURAL JOIN books AS b (book_id)
GROUP BY b.title
ORDER BY num_shipped DESC;
-- view 사용
SELECT * FROM recent_shipments;
SELECT * FROM recent_shipments ORDER BY max DESC LIMIT 3;
-- view 삭제
DROP VIEW recent_shipments;
SELECT COUNT(*) AS num_shipped, MAX(ship_date), title
FROM shipments
JOIN editions USING (isbn)
NATURAL JOIN books AS b (book_id)
GROUP BY b.title
ORDER BY num_shipped DESC;
-- view 만들기
CREATE VIEW recent_shipments
AS SELECT count(*) AS num_shipped, MAX(ship_date), title
FROM shipments
JOIN editions USING (isbn)
NATURAL JOIN books AS b (book_id)
GROUP BY b.title
ORDER BY num_shipped DESC;
-- view 사용
SELECT * FROM recent_shipments;
SELECT * FROM recent_shipments ORDER BY max DESC LIMIT 3;
-- view 삭제
DROP VIEW recent_shipments;
'DataBase' 카테고리의 다른 글
PosgreSQL - 상속 (0) | 2009.05.02 |
---|---|
PostgreSQL - FOREIGN KEY (0) | 2009.05.02 |
PostgreSQL - SUB_QUERY (0) | 2009.05.02 |
PostgreSQL - DELETE (0) | 2009.05.02 |
PostgreSQL - UPDATE (0) | 2009.05.02 |