postgresql Postgres SQL - SQL错误[42 P01]:错误:表“orders_line_items”缺少FROM-clause条目

nx7onnlm  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(274)

我正在与下面的查询中的主题错误作斗争:似乎错误是在所指示的行中;我需要指定orders__line_items.id否则'id'是模糊的。我已经尝试了各种组合的括号,全名等。.

SELECT
    orders__line_items.id::character varying AS id,   <-- ERROR SEEMS TO BE HERE
    CAST(orlin.created_at::timestamptz AS date) AS timestamp,
    orlin.price_set__shop_money__amount AS price,
    orlin.quantity AS quantity,
    orlin._sdc_source_key_id as prova,
    orlin.product_id as product_id
  FROM
    (SELECT * FROM orders__line_items
    LEFT JOIN shopify_a100."orders" ON _sdc_source_key_id = 
shopify_a100."orders"."id"
    LEFT JOIN shopify_a100."products" ON "product_id" = 
shopify_a100."products"."id") AS orlin

字符串

evrscar2

evrscar21#

发生错误的原因是SELECT无法识别orders__line_items,您必须在子查询中准备选定的列。
如果id是唯一一个不明确的列,这里有一个解决方案:

SELECT
    orlin.id,
    CAST(orlin.created_at::timestamptz AS date) AS timestamp,
    orlin.price_set__shop_money__amount AS price,
    orlin.quantity AS quantity,
    orlin._sdc_source_key_id as prova,
    orlin.product_id as product_id
FROM (
  SELECT orders__line_items.id,
         created_at,
         price_set__shop_money__amount,
         quantity,
         _sdc_source_key_id,
         product_id
  FROM orders__line_items
  LEFT JOIN shopify_a100."orders" ON _sdc_source_key_id = shopify_a100."orders"."id"
  LEFT JOIN shopify_a100."products" ON "product_id" = shopify_a100."products"."id"
) AS orlin

字符串

相关问题