Hotel guests from nested JSON

Hotel guests from nested JSON

You work at the SunTrail tour operator. A partner booking system sends every reservation as a JSONB payload: a guest object with the guest name, holding a nested contact object with city and email. The guest-care team needs a list of guests with their cities to send regional arrival guides. Some bookings arrive without the contact block — include those guests too, just without a city. Return columns: - booking_id — booking number (integer); - hotel — hotel name (a regular table column); - guest_name — the guest name from guest.name, as text; - guest_city — the city from guest.contact.city, as text; NULL when the contact or the city is absent. Sort by booking_id ascending. One row per booking, no filtering.

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.

booking_idhotelguest_nameguest_city
1Palm Bay ResortAlice RoyLyon
2Palm Bay ResortMarco DelucaTurin
3Cedar LodgeJane WuNULL
PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid