简体   繁体   中英

Teradata SQL - Create temporary table

Is it possible to create a temporary table in a select statement.

So say I would like to have the dataset with the values (1,2,3,4,5) in a column ACCOUNT_NO.

SELECT ACCOUNT_NO FROM (1,2,3,4,5)
WHERE ACCOUNT_NO NOT IN (SELECT ACCOUNT_NO FROM OTHER_TABLE)

Do you want a CTE?

WITH a as (
      SELECT a.*
      FROM ((SELECT 1 as ACCOUNT_NO) UNION ALL
            (SELECT 2 as ACCOUNT_NO) UNION ALL
            (SELECT 3 as ACCOUNT_NO) UNION ALL
            (SELECT 4 as ACCOUNT_NO) UNION ALL
            (SELECT 5 as ACCOUNT_NO)
           ) a
     )
SELECT a.ACCOUNT_NO 
FROM a
WHERE a.ACCOUNT_NO NOT IN (SELECT ot.ACCOUNT_NO FROM OTHER_TABLE ot)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM