我有一张车库的桌子。我允许API查询,该查询也应该能够返回车库的运行时间。操作时间与TimeBlock表中的车库有关。
TimeBlock表:
- open_at
- close_at
- day_of_week(0-6)
- is_24hr
- is_closed
- garage_id
这是我当前的查询。有没有办法增强它还能为每个Garage表返回7个TimeBlock条目?
select g.name, bool_or(c.garage_id is not null)
from
garage g
left join
car c on g.garage_id = c.garage_id
group by g.name
数据示例:
GarageA(id = 10)
name =“gA”
TimeBlock:
- open_at = 800
- close_at = 2000
- day_of_week = 0
- is_24hr = false
- is_closed = false
- garage_id = 10
TimeBlock:
- open_at = 800
- close_at = 2000
- day_of_week = 1
- is_24hr = false
- is_closed = false
- garage_id = 10
等。 (X7)
GarageB(id = 20)
name =“gB”
TimeBlock:
- open_at = 800
- close_at = 2000
- day_of_week = 0
- is_24hr = false
- is_closed = false
- garage_id = 20
TimeBlock:
- open_at = 800
- close_at = 2000
- day_of_week = 1
- is_24hr = false
- is_closed = false
- garage_id = 20
等。 (X7)
谢谢!