oracle: 你能指定假名优惠吗? from?

您可以在句子中分配一个假名 from? 喜欢:


select a - b "Markup" from retail a, cost b;


EDIT: 对不起,我太快得分,并试图简化这个问题,以便他没有任何意义

事实上,我正在尝试使用别名来比较同一表中的两个出版日期之间的几个月。 这就是我找到的工作:


select distinct to_char/months_between//select distinct pubdate
from books3
where pubid = 2/,
/select distinct pubdate
from books3
where pubid = 4//, '99.99'/ "Answer"
from books3


我希望它看起来像这样:


select distinct months_between/a,b/
from /select distinct pubdate
from books3
where pubid = 2 as a/,
/select distinct pubdate
from books3
where pubid = 4 as b/


但它不起作用
已邀请:

涵秋

赞同来自:

是的, Oracle 支持表假名。 它支持
AS

在列表中
SELECT

, 但不是在列表中
FROM

:


SELECT a.col - b.col AS markup
FROM RETAIL a,
COST b
WHERE b.id = a.id


大多数数据库支持关键字跳过
AS

.

但是,表伪异失制不是列的假名,您仍然需要在提议中引用相关表中的特定列 SELECT, 正如您在我的榜样更新中看到的那样。 我还增加了标准
WHERE

, 为了要求未能退回笛卡尔的工作。

派生表有时需要表假名/内置陈述 /Podzapros. AKA, 虽然我发现术语非常模糊/:


SELECT x.col
FROM /SELECT t.col,
MAX/t.date/
FROM TABLE t
GROUP BY t.col/ x


以下为您的要求:

您的问题是,您将在派生表中放置桌子别名 brackets/parenthesis:


SELECT DISTINCT TO_CHAR/MONTHS_BETWEEN/x.pubdate, y.pubdate/, '99.99'/ AS "Answer"
FROM /SELECT DISTINCT a.pubdate FROM BOOKS3 a WHERE a.pubid = 2/ x,
/SELECT DISTINCT b.pubdate FROM BOOKS3 b WHERE b.pubid = 4/ y


你需要的原因 distinct, 在于笛卡尔的工作。

卫东

赞同来自:

最接近你拥有的事实,它会移动
AS alias

从次码边


select distinct months_between/a.pubdate,b.pubdate/
from /select distinct pubdate
from books3
where pubid = 2/ as a ,
/select distinct pubdate
from books3
where pubid = 4/ as b;


但仍然,这个问题没有很大的意义。 如果有 2 参赛作品
pubid=2

和 3 为了
pubid=4

, 你得到 6 输出线....


months_between/a1, b1/
months_between/a2, b1/
months_between/a1, b2/
months_between/a2, b2/
months_between/a1, b3/
months_between/a2, b3/


我怀疑你真的有一些分组,所以它会比较记录 pubid=2 和 pubid=4 在水平 per-bookid.


select
bookid,
to_char/months_between/
max/case when pubid=2 then pubdate end/,
max/case when pubid=4 then pubdate end//, '99.99'/ "Answer"
from books
group by bookid;

要回复问题请先登录注册