如何通过with语句在Postgresql中联接3个表

时间:2019-01-03 23:01:31

标签: sql postgresql

无法使该sql运行。一直说seat_group_unique_id不存在。我正在尝试查找当前正在销售的商品是否与带有库存的表midas_input_index相匹配,但是库存表没有列seat_group_unique_id

with allonsale as (select seat_group_unique_id, event_unique_id ) 
select * from allonsale  a1 
left join recommendations.midas_input_indexed a2 on a1.seat_group_unique_id = a2.seat_group_unique_id
left join ticketing.seat_groups a3 on a3.seat_group_unique_id = a2.seat_group_unique_id
left join ticketing.inventory a4 on a4.event_unique_id = a3.event_unique_id
and a1.event_unique_id = a3.event_unique_id  
where a2.seat_group_unique_id is null

1 个答案:

答案 0 :(得分:0)

您的SQL需要添加缺少的内容:FROM语句和要从中检索数据的表。

with allonsale as (select seat_group_unique_id, event_unique_id FROM yourtable)

(...)

您将在POSTGRESQL官方网站上找到所有信息:

https://www.postgresql.org/docs/9.1/queries-with.html