PROBLEM 3 Moretown 3757 Wines Lane 700 Not rented 4 Owatonna 314 Pritchard Court 500 Rented 5 Grayslake 3234 Cunningham Court 600 Rented 6 Great Neck 1927 Romines Mill Road 900 Not rented Write a query to output the apartments whose prices are greater than the average and are also not rented, sorted by the "Price' column. Recall the AVG keyword. CODE RESULT

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please solve this problem in r programming

# Apartments

## Problem

You want to rent an apartment and have the following table named **Apartments**:

| id | city       | address             | price | status     |
|----|------------|---------------------|-------|------------|
| 1  | Las Vegas  | 732 Hall Street     | 1000  | Not rented |
| 2  | Marlboro   | 985 Huntz Lane      | 800   | Not rented |
| 3  | Moretown   | 3757 Wines Lane     | 700   | Not rented |
| 4  | Owatonna   | 314 Pritchard Court | 500   | Rented     |

At the bottom of the table, there is a green button labeled "START SOLVING."

This table lists various apartments including their city, address, price, and rental status. Each apartment is uniquely identified by an ID number.

The current status of rental is indicated in the "status" column, where "Not rented" means the apartment is currently available for rent, and "Rented" means the apartment is already rented out. This table helps potential renters quickly compare different apartments based on their location, price, and availability.
Transcribed Image Text:# Apartments ## Problem You want to rent an apartment and have the following table named **Apartments**: | id | city | address | price | status | |----|------------|---------------------|-------|------------| | 1 | Las Vegas | 732 Hall Street | 1000 | Not rented | | 2 | Marlboro | 985 Huntz Lane | 800 | Not rented | | 3 | Moretown | 3757 Wines Lane | 700 | Not rented | | 4 | Owatonna | 314 Pritchard Court | 500 | Rented | At the bottom of the table, there is a green button labeled "START SOLVING." This table lists various apartments including their city, address, price, and rental status. Each apartment is uniquely identified by an ID number. The current status of rental is indicated in the "status" column, where "Not rented" means the apartment is currently available for rent, and "Rented" means the apartment is already rented out. This table helps potential renters quickly compare different apartments based on their location, price, and availability.
### Apartments Data Analysis

**Objective:**
Write a SQL query to output the apartments whose prices are greater than the average and are also not rented, sorted by the 'Price' column. Recall the **AVG** keyword to perform the necessary calculation.

**Data Table:**
The table below lists various apartments, including their location details, prices, and rental status.

| ID  | City       | Address                  | Price (USD) | Status     |
|-----|------------|--------------------------|-------------|------------|
| 3   | Moretown   | 3757 Wines Lane          | 700         | Not rented |
| 4   | Owatonna   | 314 Pritchard Court      | 500         | Rented     |
| 5   | Grayslake  | 3234 Cunningham Court    | 600         | Rented     |
| 6   | Great Neck | 1927 Romines Mill Road   | 900         | Not rented |

**Instructions:**
1. Calculate the average price of all listed apartments.
2. Identify apartments with a price greater than this average.
3. Filter the results to show only apartments that are not rented.
4. Sort the final output by the 'Price' column in ascending order.

**Note:**
- Use the SQL **AVG** aggregate function to calculate the average price.
- Ensure your query accurately filters and sorts according to the given criteria.

**Example Query:**
```sql
SELECT * 
FROM Apartments 
WHERE Price > (SELECT AVG(Price) FROM Apartments) 
AND Status = 'Not rented' 
ORDER BY Price ASC;
```

**Learning Goals:**
- Understand the use of aggregate functions in SQL.
- Practice filtering datasets based on specific conditions.
- Gain experience with sorting query results.

Feel free to start your query and solve the problem by using the interface provided. Click the "START SOLVING" button to begin.
Transcribed Image Text:### Apartments Data Analysis **Objective:** Write a SQL query to output the apartments whose prices are greater than the average and are also not rented, sorted by the 'Price' column. Recall the **AVG** keyword to perform the necessary calculation. **Data Table:** The table below lists various apartments, including their location details, prices, and rental status. | ID | City | Address | Price (USD) | Status | |-----|------------|--------------------------|-------------|------------| | 3 | Moretown | 3757 Wines Lane | 700 | Not rented | | 4 | Owatonna | 314 Pritchard Court | 500 | Rented | | 5 | Grayslake | 3234 Cunningham Court | 600 | Rented | | 6 | Great Neck | 1927 Romines Mill Road | 900 | Not rented | **Instructions:** 1. Calculate the average price of all listed apartments. 2. Identify apartments with a price greater than this average. 3. Filter the results to show only apartments that are not rented. 4. Sort the final output by the 'Price' column in ascending order. **Note:** - Use the SQL **AVG** aggregate function to calculate the average price. - Ensure your query accurately filters and sorts according to the given criteria. **Example Query:** ```sql SELECT * FROM Apartments WHERE Price > (SELECT AVG(Price) FROM Apartments) AND Status = 'Not rented' ORDER BY Price ASC; ``` **Learning Goals:** - Understand the use of aggregate functions in SQL. - Practice filtering datasets based on specific conditions. - Gain experience with sorting query results. Feel free to start your query and solve the problem by using the interface provided. Click the "START SOLVING" button to begin.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY