私はこの問題に約8時間取り組んできましたが、成功しませんでした。誰にもアイデアはありますか?
問題: 正しいテーブルを使用して、希望するいずれかの結合操作を使用してサブクエリを作成します。これにより、顧客番号、姓と名を連結したもの、および最も高価な本を注文したすべての顧客の市区町村 (小売価格に基づく) がリストされます。価格)。「顧客名」の列と別名を組み合わせた顧客名を与えます。
これが私のコードです:
SELECT book_customer.customerid, lastname || ', ' || firstname AS "Customer Name", city
FROM book_customer, book_order, order_items
WHERE book_customer.customerid = book_order.customerid
AND book_order.orderid = order_items.orderid
AND bookid =
(
SELECT MAX(retail)
FROM books
GROUP BY bookid
)
;
結果:
SQL> SELECT book_customer.customerid, lastname || ', ' || firstname AS "Customer Name", city
2 FROM book_customer, book_order, order_items
3 WHERE book_customer.customerid = book_order.customerid
4 AND book_order.orderid = order_items.orderid
5 AND bookid =
6 (
7 SELECT MAX(retail)
8 FROM books
9 GROUP BY bookid
10 )
11 ;
SELECT MAX(retail)
*
ERROR at line 7:
ORA-01427: single-row subquery returns more than one row
私もこれを試しました:
SELECT customerid, lastname || ', ' || fistname AS "Customer Name", city
FROM book_customer, book_order
WHERE book_customer.customerid = book_order.customerid
AND orderid =
(
SELECT orderid
FROM order_items
AND bookid =
(
SELECT bookin
FROM books
GROUP BY bookid
HAVING MAX(retail)
)
)
;
結果:
SQL> SELECT customerid, lastname || ', ' || fistname AS "Customer Name", city
2 FROM book_customer, book_order
3 WHERE book_customer.customerid = book_order.customerid
4 AND orderid =
5 (
6 SELECT orderid
7 FROM order_items
8 AND bookid =
9 (
10 SELECT bookid
11 FROM books
12 GROUP BY bookid
13 HAVING MAX(retail)
14 )
15 )
16 ;
AND bookid =
*
ERROR at line 8:
ORA-00907: missing right parenthesis
ERD
Book_Customer TABLE
CustomerID PK
Lastname
Firstname
Address
City
State
Zip
Referred
Book_Order TABLE
OrderID PK
CustomerID FK
OrderDate
ShipDate
ShipStreet
ShipCity
ShipState
ShipZip
Order_Items TABLE
OrderID PK/FK
ItemNum PK/FK
BookID
Quantity
Books TABLE
BookID PK
ISBN
Title
PubDate
PubID FK
Cost
Retail
Category
どんな助けでも大歓迎です。