+ 3
The "17 Code Project" question left me confused about columns named with clause key words--Please help!
Bear with me for this question pls! The problem was: Write a query to output the apartments whose prices are greater than the average and are also not rented, sorted by price. The actual code that ran successfully was: SELECT * FROM Apartments WHERE price >= (SELECT AVG(price) FROM apartments) ORDER BY price The problem was a little difficult for me because it also asks to include, as part of the query, apartments whose status is "not rented". So, what I'd like to know is, how would I write that part of the query when the word "status" is recognized as a clause but in this problem "status" was also the name of a column of the apartments table?
9 odpowiedzi
+ 2
As far as I can tell "status" is not a keyword in SQL. Apparently it is in MySQL. Here is a stack overflow thread about what to do in MySQL:
https://stackoverflow.com/questions/6427352/a-column-called-status-in-mysql
+ 2
Thanks Simon Sauter I was asking because the word “status” turns purple as do the SELECT, WHERE, FROM, and ORDER BY clauses.
I appreciate all your help!!
+ 1
In theory that code should not be accepted as correct. The reason that it is accepted has to do with the way sololearn evaluates codes. All it does is compare the output of your code to the expected output. If it is identical your code is accepted as correct, if it is not your code is rejected.
In this case the output is the same whether you add the condition that the apartment has to be "not rented" or not for the simple reason that there is no apartment which is rented and has an above average price.
+ 1
Simon Sauter and thanks for the stackoverflow link!!!! 😩🙏
+ 1
Strange, for me "status" shows up white. Both on the SL website and in the android app.
+ 1
🥲 then why is it appearing in purple on SL on my iphone 😩
+ 1
Maybe they use a different syntax highlighter in the iPhone app.
+ 1
Sololearn uses PostgreSQL 13.0. You can check by running "SELECT VERSION()".
According to the documentation "status" is not a keyword in PostgreSQL.
https://www.postgresql.org/docs/current/sql-keywords-appendix.html
0
Sololearn accepts this without error:
WHERE
status = 'Not rented'