SQL Plus - 别名类型问题

发布于 2024-08-12 10:53:02 字数 466 浏览 5 评论 0原文

我需要找到每本书的图书代码和书名,其价格大于每本类型为“HOR”的图书的图书价格。我的桌子看起来像这样,

CREATE TABLE BOOK (
   BOOK_CODE CHAR(4) CONSTRAINT BOOK_BOOK_CODE_PK PRIMARY KEY, 
   TITLE VARCHAR2(40) CONSTRAINT BOOK_TITLE_NN NOT NULL, 
   PUBLISHER_CODE CHAR(2) CONSTRAINT BOOK_PUBLISHER_CODE_FK REFERENCES PUBLISHER(PUBLISHER_CODE),
   TYPE CHAR(3), (this is where the 'HOR' is located)
   PRICE NUMBER(4,2), 
   PAPERBACK CHAR(1) 
);

我尝试了几种不同的方法,但我不知所措。我假设我必须使用别名?

I need to find the book code and book title for each book whose price is greater than the book price for every book that has the type 'HOR'. My table looks like this

CREATE TABLE BOOK (
   BOOK_CODE CHAR(4) CONSTRAINT BOOK_BOOK_CODE_PK PRIMARY KEY, 
   TITLE VARCHAR2(40) CONSTRAINT BOOK_TITLE_NN NOT NULL, 
   PUBLISHER_CODE CHAR(2) CONSTRAINT BOOK_PUBLISHER_CODE_FK REFERENCES PUBLISHER(PUBLISHER_CODE),
   TYPE CHAR(3), (this is where the 'HOR' is located)
   PRICE NUMBER(4,2), 
   PAPERBACK CHAR(1) 
);

I have tried several different ways but I am at a loss. I am assuming I will have to use an alias?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆で 2024-08-19 10:53:02

未必。您可以像这样使用嵌套 SELECT:

SELECT
    BOOK_CODE,
    TITLE
FROM
    BOOK
WHERE
    PRICE > (SELECT MAX(PRICE) FROM BOOK WHERE TYPE = 'HOR'))

Not necessarily. You could use a nested SELECT like this:

SELECT
    BOOK_CODE,
    TITLE
FROM
    BOOK
WHERE
    PRICE > (SELECT MAX(PRICE) FROM BOOK WHERE TYPE = 'HOR'))
站稳脚跟 2024-08-19 10:53:02
SELECT a.book_code, a.title
FROM book a, book b
WHERE a.price > b.price
AND b.type = 'HOR'

可能吗?

SELECT a.book_code, a.title
FROM book a, book b
WHERE a.price > b.price
AND b.type = 'HOR'

Possibly?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文