Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
973 B
3
Indexable
Never
/* Заполнение таблицы model_lesson.f_order */
INSERT INTO model_lesson.f_order (order_id, create_dttm, shop_id, product_id, item_count, customer_id, order_status)
SELECT o.order_id as order_id, 
    o.create_dttm as create_dttm,
    s.shop_id as shop_id,
    p.product_id as product_id,
    o.item_count as item_count,
    c.customer_id as customer_id,
    o.order_status as order_status 
FROM source4.order o
  JOIN model_lesson.d_address a_shop ON o.shop_address::text = a_shop.address_json::text
  JOIN model_lesson.d_address customer_a ON o.customer_address::text = customer_a.address_json::text
  JOIN model_lesson.d_product p ON o.product_name = p.product_name
  JOIN model_lesson.d_shop s ON o.shop_name = s.shop_name AND a_shop.address_id = s.shop_address_id
  JOIN model_lesson.d_customer c ON o.customer_name = c.customer_name AND o.customer_phone_number = c.customer_phone_number AND customer_a.address_id = c.customer_address_id; 
Leave a Comment