임시 테이블 만들기

SQL로 하는 탐색적 데이터 분석

Christina Maimone

Data Scientist

구문

임시 테이블 생성 구문

-- Create table as
CREATE TEMP TABLE new_tablename AS 
-- Query results to store in the table
SELECT column1, column2 
  FROM table;

SELECT INTO 구문

-- Select existing columns
SELECT column1, column2 
  -- Clause to direct results to a new temp table
  INTO TEMP TABLE new_tablename 
  -- Existing table with exisitng columns
  FROM table;
SQL로 하는 탐색적 데이터 분석

테이블 생성

CREATE TEMP TABLE top_companies AS
SELECT rank, 
       title 
  FROM fortune500
 WHERE rank <= 10;
SELECT * 
  FROM top_companies;
 rank |       title        
------+--------------------
    1 | Walmart
    2 | Berkshire Hathaway
    3 | Apple
    4 | Exxon Mobil
    5 | McKesson
    6 | UnitedHealth Group
    7 | CVS Health
    8 | General Motors
    9 | AT&T
   10 | Ford Motor
(10행)
SQL로 하는 탐색적 데이터 분석

테이블에 삽입

INSERT INTO top_companies
SELECT rank, title 
  FROM fortune500 
 WHERE rank BETWEEN 11 AND 20;
SELECT * FROM top_companies;
 rank |          title           
------+--------------------------
    1 | Walmart
    2 | Berkshire Hathaway
    3 | Apple
...
    9 | AT&T
   10 | Ford Motor
   11 | AmerisourceBergen
   12 | Amazon.com
   13 | General Electric
   14 | Verizon
   15 | Cardinal Health
   16 | Costco
   17 | Walgreens Boots Alliance
   18 | Kroger
   19 | Chevron
   20 | Fannie Mae
(20행)

SQL로 하는 탐색적 데이터 분석

테이블 삭제(DROP)

DROP TABLE top_companies;
DROP TABLE IF EXISTS top_companies;
SQL로 하는 탐색적 데이터 분석

이제 테이블을 만들어 봅시다!

SQL로 하는 탐색적 데이터 분석

Preparing Video For Download...