将两个 PL/SQL select 语句的结果相除

发布于 2024-07-23 14:03:54 字数 133 浏览 7 评论 0原文

我的两个 PL/SQL select 语句的结果是整数 27 和 27。 50,我希望输出除法 (27/50) 0.54...该怎么做?

我努力了 从中选择* ((选择...)/(选择...)) 但它不起作用!

The results of my two PL/SQL select statements are integers 27 & 50, I want their division (27/50) 0.54 at output...how to do that?

I have tried
select * from
((select....)/(select ...))
but it does not work!!

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

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

发布评论

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

评论(2

任谁 2024-07-30 14:03:54
SELECT 
  (SELECT thefirst FROM singlerowtable) / 
  (SELECT theother FROM othersinglerow) AS result

如果您想确保 FLOAT 除法,也可以使用 CAST(thefirst AS FLOAT),&c。

SELECT 
  (SELECT thefirst FROM singlerowtable) / 
  (SELECT theother FROM othersinglerow) AS result

You can also use CAST(thefirst AS FLOAT) if you want to ensure a FLOAT division, &c.

明天过后 2024-07-30 14:03:54

在 FROM 子句中,您只能将结果集连接在一起,不能使用其他类似的运算符。

但是,您可以在 SELECT 子句中使用算术运算符,例如(正如 Alex 已经说过的那样):

SELECT (SELECT thefirst ...)
       /
       (SELECT thesecond ...) AS result
FROM DUAL;

或者,

SELECT A.thefirst / B.thesecond AS result
FROM   (SELECT thefirst ...) A
      ,(SELECT thesecond ...) B;

如果结果集不恰好只有一行,则第一种方法将失败。

即使结果集有多于一行,第二种方法也将起作用 - 如果您不希望两个结果集之间进行笛卡尔连接,则可能必须提供 A 和 B 之间的连接条件。

In your FROM clause you can only join result sets together, you can't use other operators like that.

You can, however, use arithmetic operators in your SELECT clause, e.g. (as Alex has already said):

SELECT (SELECT thefirst ...)
       /
       (SELECT thesecond ...) AS result
FROM DUAL;

or, alternatively:

SELECT A.thefirst / B.thesecond AS result
FROM   (SELECT thefirst ...) A
      ,(SELECT thesecond ...) B;

The first approach will fail if the result sets do not have exactly one row each.

The second approach will work even if the result sets have more than one row - you may have to supply join criteria between A and B if you don't want a cartesian join between the two result sets.

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