提出的问题是这样的:
价格在 50.00 美元或以下的二手书的书名、作者姓名和价格是什么?结果应按价格降序排列,然后按 AZ 顺序排列标题。
代码:
SELECT book.title, author.LastName, author.firstName, Ownersbook.price
FROM book, author, ownersbook
ON book.isbn = bookauthor.isbn
WHERE Ownersbook.price < 50
ORDER BY Ownersbook.price DESC, book.title ASC;
我希望表格看起来像这样:
+-------------------------------------------------+------------+-----------+-------+
| title | lastname | firstname | price |
+-------------------------------------------------+------------+-----------+-------+
| ER, SOM, NF, DK/NF, SQL, JDBC, ODBC, and RELVAR | Stratton | Bill | 50.00 |
| My Love's Last Longing | Heartthrob | Danielle | 50.00 |
| How to Keep your Cable Bill Down | Hartpence | Bruce | 45.00 |
| Yes! Networking is for Bills Fans | Lutz | Peter | 40.00 |
| Yes! Networking is for Bills Fans | Phelps | Andrew | 40.00 |
| Yes! Networking is for Bills Fans | Leone | James | 40.00 |
| The Shortest Book in the World | Phelps | Andrew | 35.00 |
| How to Keep your Cellular Bill Down | Hartpence | Bruce | 25.00 |
| My Lost Love's Long Last Lingering | Heartthrob | Danielle | 25.00 |
| From the Shores of Lake Erie to IT | Stratton | Bill | 0.00 |
+-------------------------------------------------+------------+-----------+-------+
10 rows in set (0.00 sec)
我试图摆脱 ON 关键字语句,但它只是永远重复了大量数据,我不希望这样。我不确定如何正确使用 ON 关键字。
错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'ON bo
ok.isbn = bookauthor.isbn
WHERE Ownersbook.price < 50
ORDER BY book.title' at line 2