-1

述べられた質問はこれでした:

価格が 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
4

3 に答える 3

1

結合なしでキーワードを使用することはできません。条件を句ONに入れる必要がありますwhere

SELECT book.title, author.LastName, author.firstName, Ownersbook.price 
FROM book, author, ownersbook 
WHERE Ownersbook.price < 50 
and book.isbn = bookauthor.isbn 
-- here you have to add condition with ownersbook and some table
-- here you have to add condition with bookauthor and some table
ORDER BY Ownersbook.price DESC, book.title ASC;

エイリアスを使用することをお勧めします。以下の例を参考にしてください

SELECT b.title, a.LastName, a.firstName, ob.price 
FROM book b, author a  ownersbook ob, bookauthor ba
WHERE ob.price < 50 
and b.isbn = ba.isbn 
-- here you have to add condition with ownersbook and some table
-- here you have to add condition with bookauthor and some table
ORDER BY ob.price DESC, b.title ASC;
于 2013-07-31T09:54:04.380 に答える