human
Schema:
Apartment_Buildings (building_id, building_short_name, building_full_name, building_description, building_address, building_manager, building_phone)
Apartments (apt_id, building_id, apt_type_code, apt_number, bathroom_count, bedroom_count, room_count)
Apartment_Facilities (apt_id, facility_code)
Guests (guest_id, gender_code, guest_first_name, guest_last_name, date_of_birth)
Apartment_Bookings (apt_booking_id, apt_id, guest_id, booking_status_code, booking_start_date, booking_end_date)
View_Unit_Status (apt_id, apt_booking_id, status_date, available_yn)
Please answer with SQL.
assistant
Sure, I understand.
human
Show the apartment type codes and the corresponding number of apartments sorted by the number of apartments in ascending order.
assistant
SELECT apt_type_code , COUNT(*) FROM Apartments GROUP BY apt_type_code ORDER BY COUNT(*) ASC
human
Show the top 3 apartment type codes sorted by the average number of rooms in descending order.
assistant
SELECT apt_type_code FROM Apartments GROUP BY apt_type_code ORDER BY avg(room_count) DESC LIMIT 3
human
Show each apartment type code, and the maximum and minimum number of rooms for each type.
assistant
SELECT apt_type_code , max(room_count) , min(room_count) FROM Apartments GROUP BY apt_type_code
human
Show the apartment type code that has the largest number of total rooms, together with the number of bathrooms and number of bedrooms.
assistant
SELECT apt_type_code , bathroom_count , bedroom_count FROM Apartments GROUP BY apt_type_code ORDER BY sum(room_count) DESC LIMIT 1
human
Show the most common apartment type code.
assistant
SELECT apt_type_code FROM Apartments GROUP BY apt_type_code ORDER BY count(*) DESC LIMIT 1
human
Show the most common apartment type code among apartments with more than 1 bathroom.
assistant
SELECT apt_type_code FROM Apartments WHERE bathroom_count > 1 GROUP BY apt_type_code ORDER BY COUNT( * ) DESC LIMIT 1 ;