on子句比较出错 - Big Query

时间:2017-11-17 12:03:30

标签: google-bigquery

以下大查询代码会出现以下错误。

select 
   selected_date date,
   pp.name property,
   bb.bookings bb,
   av.available vailable,
from 
(SELECT DATE(DATE_ADD(TIMESTAMP("2017-10-01"), pos - 1, "DAY")) AS selected_date
FROM (
     SELECT ROW_NUMBER() OVER() AS pos, *
     FROM (FLATTEN((
     SELECT SPLIT(RPAD('', 1 + DATEDIFF(TIMESTAMP(CURRENT_DATE()), TIMESTAMP("2017-10-01")), '.'),'') AS h
     FROM (SELECT NULL)),h
)))) v
   cross join
 (select p.name name from [roomsproperties.properties] p where p.name not like '%test%' group by name) as pp

 left join 
 (select sum(b.rooms) bookings,
        p.name property,
        b.checkin checkin,
        b.checkout checkout
        from [bookings.bookings] b
        left join [roomsproperties.rooms] r on r.id = b.room_id
            left join [roomsproperties.properties] p on p.id = r.property_id
        where p.name not like '%test%'
        and b.status not in('Rejected', 'Cancelled - By customer', 'OTP Not Varified')
        group by property,checkin,checkout
        ) as bb on pp.name = bb.property and (v.selected_date between bb.checkin and bb.checkout)

left join
(select sum(r.quantity) available, 
         p.name property,
         date(r.created_at) date
         from [roomsproperties.rooms] r 
         left join [roomsproperties.properties] p on p.id = r.property_id 
         group by property, date
         ) av on pp.name = av.property and v.selected_date >= av.date 

错误是,

错误:ON子句必须为AND =每个表中一个字段名称的比较,所有字段名称都以表名为前缀。考虑使用标准SQL

任何人都可以提供帮助

1 个答案:

答案 0 :(得分:0)

你应该尝试:

(select ...) as bb on pp.name = bb.property
WHERE v.selected_date  between bb.checkin and bb.checkou

(select ...) as av on pp.name = av.property 
WHERE v.selected_date >= av.date