Where am i wrong in this 'apartment' project in SQL | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 4

Where am i wrong in this 'apartment' project in SQL

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;

23rd Dec 2020, 8:58 AM
คгשเภ๔ кย๓คг
คгשเภ๔ кย๓คг - avatar
27 Answers
+ 54
SELECT * FROM Apartments WHERE Price > ( SELECT AVG ( Price ) FROM Apartments ) AND status = 'Not rented' ORDER BY Price This is correct👍😍
27th Jan 2021, 8:16 PM
Thelli
Thelli - avatar
+ 9
SELECT * FROM apartments WHERE price > (SELECT AVG (price) FROM apartments ) ORDER BY price ASC;
17th Jan 2021, 4:49 PM
Manvendra Yadav
Manvendra Yadav - avatar
+ 3
Arvind Kumar Well no need to check city in because you need all cities in which appartments are not rented and Price has great than or equal to average. So you need a subquery also. Check this SELECT * FROM Apartments WHERE Price >= (SELECT avg(Price) FROM Apartments) AND status = Not rented ORDER BY Price;
23rd Dec 2020, 9:13 AM
A͢J
A͢J - avatar
+ 3
Arvind Kumar It will work. You just have to put Not rented in single quotes. Not rented is a string so you must know in SQL we have to put string in single quotes.
23rd Dec 2020, 3:43 PM
A͢J
A͢J - avatar
+ 3
This is working. Finally, I got it. I'm really tired. SELECT * FROM apartments WHERE price > (SELECT AVG(price) FROM apartments) ORDER BY price
8th Jan 2021, 6:37 AM
MATHAVY UMASUTHASARMA
MATHAVY UMASUTHASARMA - avatar
+ 3
SELECT * FROM Apartments WHERE Price > ( SELECT AVG ( Price ) FROM Apartments ) AND status = 'Not rented' ORDER BY Price i applied the same but it still says not correct!!
31st Mar 2021, 8:51 AM
Sirisha Tammina
Sirisha Tammina - avatar
+ 2
I Am Groot ! Sorry this not working
23rd Dec 2020, 10:31 AM
คгשเภ๔ кย๓คг
คгשเภ๔ кย๓คг - avatar
+ 2
It is not working
22nd Feb 2021, 5:23 AM
Rajesh Mandavi
Rajesh Mandavi - avatar
+ 2
I tried in every possible way it doesn't work,, The only error it always shows me is lowercase & uppercase,,I even changed all the starting letters of string to uppercase but in 'Not rented' Only N should be in uppercase other all should be in lowercase,,but once I change the starting letters of the string to uppercase i get 'Not Rented'!!! In Rented R should be in lowercase,,but i can't change it!! Do you guys know any way to uppercase only frst letter 'N' but not 'R'?????
3rd May 2021, 4:32 AM
Anniee
Anniee - avatar
+ 1
MATHAVY UMASUTHASARMA and ssm could you please explain why it works? There is no query to get 'not rented' apartments.
10th Jan 2021, 4:30 PM
Abhinav
+ 1
SELECT * FROM apartments WHERE price > (SELECT AVG(price) FROM apartments) ORDER BY price this is the answer
23rd Apr 2021, 10:31 AM
Anshuman Raj
Anshuman Raj - avatar
+ 1
SELECT * FROM Apartments WHERE price >= (SELECT AVG(price) FROM Apartments ) ORDER BY price; This is correct 💯
11th Dec 2021, 7:17 PM
MN FATHIMA RIHAM - s92064451 -321424451
MN FATHIMA RIHAM - s92064451 -321424451 - avatar
+ 1
I forgot about the nested query🙈 I wrote like this. This request passed the test😎 SELECT * FROM Apartments WHERE (price >= 750 AND status='Not rented') ORDER BY price
13th Apr 2022, 11:23 AM
Liza Belova
Liza Belova - avatar
0
ssm I tried something similar, but it didn't work!...
6th Jan 2021, 11:01 PM
Barbu Vulc
Barbu Vulc - avatar
0
Try this 👇🏻 SELECT * FROM apartments WHERE price > (SELECT AVG(price) FROM apartments) ORDER BY price
18th Feb 2021, 12:59 PM
PRASHANT VERMA
PRASHANT VERMA - avatar
0
SELECT * FROM apartments WHERE price > (SELECT AVG(price) FROM apartments) ORDER BY price
15th Mar 2021, 5:49 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
0
actually i got it now, the issue is with the app. once i closed the app and reipened it again and tried the same query it worked!
31st Mar 2021, 9:04 AM
Sirisha Tammina
Sirisha Tammina - avatar
0
SELECT * FROM apartments where price >( SELECT AVG (price)FROM apartments ) and status='Not rented' ORDER by price;
27th Sep 2021, 7:24 AM
Sandhya.v
Sandhya.v - avatar
0
SELECT * FROM Apartments WHERE Price > ( SELECT AVG ( Price ) FROM Apartments ) AND status = 'Not rented' ORDER BY Price this is right
2nd Nov 2021, 4:42 PM
michael
michael - avatar
0
SELECT * FROM APARTMENTS WHERE PRICE > (SELECT AVG(PRICE) FROM APARTMENTS) ORDER BY PRICE; This will work
11th Dec 2021, 10:13 AM
Adarsh Chaudhary
Adarsh Chaudhary - avatar