2015-12-01 63 views
3

我需要珍惜的數據急使用臨時表我的SQL查詢:臨時表SQL普雷斯托

CREATE TEMPORARY TABLE fakehours (Hour BIGINT); 

INSERT INTO Hour VALUES (0); 
INSERT INTO Hour VALUES (1); 
INSERT INTO Hour VALUES (2); 
INSERT INTO Hour VALUES (3); 
INSERT INTO Hour VALUES (4); 
INSERT INTO Hour VALUES (5); 
INSERT INTO Hour VALUES (6); 
INSERT INTO Hour VALUES (7); 
INSERT INTO Hour VALUES (8); 
INSERT INTO Hour VALUES (9); 
INSERT INTO Hour VALUES (10); 
INSERT INTO Hour VALUES (11); 
INSERT INTO Hour VALUES (12); 
INSERT INTO Hour VALUES (13); 
INSERT INTO Hour VALUES (14); 
INSERT INTO Hour VALUES (15); 
INSERT INTO Hour VALUES (16); 
INSERT INTO Hour VALUES (17); 
INSERT INTO Hour VALUES (18); 
INSERT INTO Hour VALUES (19); 
INSERT INTO Hour VALUES (20); 
INSERT INTO Hour VALUES (21); 
INSERT INTO Hour VALUES (22); 
INSERT INTO Hour VALUES (23); 

我能做些什麼在普雷斯托這樣嗎?

回答

0

根據您的Presto版本試試:

SELECT * FROM UNNEST(SEQUENCE(0,23)) 

SELECT * FROM UNNEST(ARRAY[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]) 

應該達到你的加入想要的東西,總之具有普雷斯托可用的臨時表。

1

Pro tipp,您甚至可以使用WITH語法在沒有臨時表的情況下離開。然後在下面的SELECT聲明中,您可以使用hours,就像它是一個表一樣。

WITH hours AS (SELECT * FROM UNNEST(ARRAY[0,1, ... 22,23]) AS t (hour)) 
SELECT 
    * 
FROM 
    hours 
; 
1

我這樣做:

CREATE TABLE fakehours AS 
WITH hours AS (
SELECT * FROM UNNEST(SEQUENCE(0,23,1)) AS t (hour) 
) 
SELECT * 
FROM hours 
;