Middle
41
Produce a list of costly bookings Question How can you produce a list of bookings on the day of [phone] which will cost the member (or guest) more than $30? Remember that guests have different costs to members (the listed costs are per half-hour 'slot'), and the guest user is always ID 0. Include in your output the name of the facility, the name of the member formatted as a single column, and the cost. Order by descending cost, and do not use any subqueries.
Сұралған компаниялар
FOM GROUP
AI-дан жауап
sobes.tech AI
Для получения списка бронирований на определённый день, где стоимость превышает $30, без использования подзапросов, можно использовать JOIN и фильтрацию в WHERE. Предположим, у нас есть таблицы bookings, members, facilities, и стоимость рассчитывается исходя из длительности и тарифа, который зависит от того, гость это (ID=0) или член.
Пример SQL-запроса:
SELECT f.name AS facility_name,
CONCAT(m.first_name, ' ', m.last_name) AS member_name,
(b.slots * CASE WHEN m.id = 0 THEN f.guest_cost_per_slot ELSE f.member_cost_per_slot END) AS cost
FROM bookings b
JOIN members m ON b.member_id = m.id
JOIN facilities f ON b.facility_id = f.id
WHERE b.booking_date = :phone
AND (b.slots * CASE WHEN m.id = 0 THEN f.guest_cost_per_slot ELSE f.member_cost_per_slot END) > 30
ORDER BY cost DESC;
Здесь:
:phone— параметр с датой бронирования.slots— количество половинчасовых интервалов.- Стоимость рассчитывается с учётом типа пользователя.
Такой запрос выводит название объекта, имя пользователя в одной колонке и стоимость, отсортированные по убыванию стоимости.