+ 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;
19th Dec 2020, 2:52 AM
A͢J
A͢J - avatar
+ 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.
17th Dec 2020, 8:21 AM
A͢J
A͢J - avatar
+ 5
SwagDragon Share your code.
17th Dec 2020, 1:13 PM
A͢J
A͢J - avatar
+ 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.
17th Dec 2020, 11:05 AM
Brian
Brian - avatar
+ 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 .
19th Dec 2020, 3:27 AM
Brian
Brian - avatar
+ 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.
19th Dec 2020, 11:30 PM
Brian
Brian - avatar
+ 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;
19th Dec 2020, 2:44 AM
Suliman Farzat
Suliman Farzat - avatar
+ 1
SwagDragon do you need further clarification on the recommended fixes?
17th Dec 2020, 1:21 PM
Brian
Brian - avatar
+ 1
Select * from apartments Where price >= 750 and status = 'not rented' Order by price
19th Dec 2020, 7:32 AM
Learnevrly
+ 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;
8th Jan 2021, 6:17 PM
David Ordás
David Ordás - avatar
0
Brian you're right
20th Dec 2020, 12:14 AM
Learnevrly
0
You manage a zoo. Each animal in the zoo comes from a different country. Here are the tables you have: Animals
25th Dec 2020, 2:36 AM
Nirmalveer Singh
Nirmalveer Singh - avatar
0
I couldnt pass the test case of apartments problem can anyone please help me
1st Jan 2021, 10:12 AM
akhila jogineedi
akhila jogineedi - avatar
0
akhila jogineedi it is best to start a new Q&A post if you want help on your own code.
1st Jan 2021, 7:16 PM
Brian
Brian - avatar