+ 10
SwagDragon
You can not compare multiple string with single string like that. And also there is no need to check string. You just have to write select query where you need to check average so you need a subquery for this.
Here is the solution
SELECT * FROM Apartments WHERE Price >= (SELECT avg(Price) FROM Apartments) AND status = Not rented ORDER BY Price;
+ 8
SwagDragon You need to check if price is greater than the average.
First get average then pass that average in where clause and compare with price to get desire output.
+ 5
SwagDragon Share your code.
+ 3
SwagDragon as I Am Groot ! indicated, you will need to add a subselect in the WHERE clause to determine the average.
Also note that it asks you to filter on status of 'Not rented', not by city.
[But to correct your query syntax, you would use: WHERE city IN ("Las Vegas", "Marlboro", ...)]
Don't forget to sort by price.
+ 3
Suliman Farzat the city selection is not in the problem statement. See https://www.sololearn.com/coach/1057?ref=app
Then study I Am Groot !'s solution .
+ 3
Learnevrly using "price >= 750" may get the job done for now, but it will likely fail as soon as there is a change in the data. Instead of manually calculating the average and hard-coding it, let SQL do the work. If you replace 750 with a subquery that returns the average then the problem is solved completely.
+ 2
SELECT * FROM apartments WHERE city in ('Las Vegas', 'Marlboro', 'Great') AND
COUNT(CASE WHEN avg(price) < price THEN 1 ELSE 0 END) AS not_rented
ORDER BY price;
+ 1
SwagDragon do you need further clarification on the recommended fixes?
+ 1
Select * from apartments
Where price >= 750 and status = 'not rented'
Order by price
+ 1
I share my solution In mysql to your problem
https://www.sololearn.com/coach/1057?ref=app
SELECT *
FROM Apartments
WHERE status = 'Not rented'
AND price > ALL (
SELECT avg(price)
FROM Apartments
)
ORDER BY price;
0
Brian you're right
0
You manage a zoo. Each animal in the zoo comes from a different country. Here are the tables you have:
Animals
0
I couldnt pass the test case of apartments problem can anyone please help me
0
akhila jogineedi it is best to start a new Q&A post if you want help on your own code.



