我想做这样的事情:
TOKEN=
在Oracle数据库上。
答案 0 :(得分:4)
您可以使用CROSS APPLY
(Oracle 12c):
select price, tax_rate, tax_amount, tax_amount+price as total
from Dual
CROSS APPLY (SELECT 999 AS price, 0.1 AS tax_rate FROM dual) s
CROSS APPLY (SELECT price*tax_rate AS tax_amount FROM dual) s2;
select price, tax_rate, tax_amount, tax_amount+price as total
from Dual
,LATERAL (SELECT 999 AS price, 0.1 AS tax_rate FROM dual) s
,LATERAL (SELECT price*tax_rate AS tax_amount FROM dual) s2;
您无法在同一级别(SELECT
引用已定义的列,但是使用CROSS APPLY
/ LATERAL JOIN
可以创建一系列计算列,而无需使用子查询。
相似的方法:PostgreSQL using a calculated column in the same query