将两个 PL/SQL select 语句的结果相除
我的两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想确保
FLOAT
除法,也可以使用CAST(thefirst AS FLOAT)
,&c。You can also use
CAST(thefirst AS FLOAT)
if you want to ensure aFLOAT
division, &c.在 FROM 子句中,您只能将结果集连接在一起,不能使用其他类似的运算符。
但是,您可以在 SELECT 子句中使用算术运算符,例如(正如 Alex 已经说过的那样):
或者,
如果结果集不恰好只有一行,则第一种方法将失败。
即使结果集有多于一行,第二种方法也将起作用 - 如果您不希望两个结果集之间进行笛卡尔连接,则可能必须提供 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):
or, alternatively:
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.