oracle中如何避免重复?

发布于 2024-11-01 01:53:03 字数 248 浏览 0 评论 0原文

SELECT title, retail, (SELECT AVG(retail)
                 FROM   books) 
FROM   books
WHERE  retail < (SELECT AVG(retail)
                 FROM   books) 

有没有办法缩短其中之一 (SELECT AVG(retail) 从书籍)到别名?

SELECT title, retail, (SELECT AVG(retail)
                 FROM   books) 
FROM   books
WHERE  retail < (SELECT AVG(retail)
                 FROM   books) 

Is there a way to shorten one of (SELECT AVG(retail)
FROM books) to an alias?

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

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

发布评论

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

评论(2

山川志 2024-11-08 01:53:03

试试这个:

SELECT *
  FROM (
    SELECT title, retail, AVG(retail) OVER() avg_retail
    FROM   books
    )
WHERE  retail < avg_retail

或使用WITH:

WITH dat AS
(
    SELECT title, retail, AVG(retail) OVER() avg_retail
    FROM   books
)
SELECT *
  FROM dat
 WHERE  retail < avg_retail

Try this:

SELECT *
  FROM (
    SELECT title, retail, AVG(retail) OVER() avg_retail
    FROM   books
    )
WHERE  retail < avg_retail

or using a WITH:

WITH dat AS
(
    SELECT title, retail, AVG(retail) OVER() avg_retail
    FROM   books
)
SELECT *
  FROM dat
 WHERE  retail < avg_retail
江南烟雨〆相思醉 2024-11-08 01:53:03

您可以使用 WITH 子句进行重构,也许像这样:

With avg_retail as
    (SELECT AVG(retail) the_avg
    FROM   books) 
SELECT title, retail, avg_retail.the_avg
from books, avg_retail
where books.retail < avg_retail.the_avg;

you could refactor with the WITH clause, maybe like this:

With avg_retail as
    (SELECT AVG(retail) the_avg
    FROM   books) 
SELECT title, retail, avg_retail.the_avg
from books, avg_retail
where books.retail < avg_retail.the_avg;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文