内部加入临时表

时间:2018-04-05 08:51:44

标签: sql postgresql

WITH  temp(k)  AS (VALUES (15252332445), (15253665080), (15241848778),
(11813086136), (15253665080) ) LEFT join hello.transaction_job B on
B.id=temp.k SELECT * FROM temp,B.id,B.msisdn

尝试使用标准表连接公用表表达式,但失败

你们能告诉我为什么吗?

error im getting when i run the query

3 个答案:

答案 0 :(得分:4)

在 JOIN之前SELECT需要与每次加入一样

WITH  temp(k)  AS (
   VALUES (15252332445), (15253665080), (15241848778),
          (11813086136), (15253665080)
)
SELECT B.id, B.msisdn
FROM temp t
  LEFT join hello.transaction_job B on  B.id = t.k; 

答案 1 :(得分:0)

也许你想要像:

WITH  temp(k)  AS (VALUES (15252332445), (15253665080), (15241848778),
(11813086136), (15253665080) ) 
, b as (select * from temp LEFT join hello.transaction_job B on
B.id=temp.k)
SELECT * FROM temp,B.id,B.msisdn

答案 2 :(得分:0)

您也可以使用cte

中的union进行书写
WITH TEMP (k)
AS (
    SELECT 15252332445

    UNION ALL

    SELECT 15253665080

    UNION ALL

    SELECT 15241848778

    UNION ALL

    SELECT 11813086136

    UNION ALL

    SELECT 15253665080
    )
SELECT B.id, B.msisdn
FROM TEMP t
LEFT JOIN hello.transaction_job B ON B.id = t.k