选择 AS 在 interbase 中不工作
Posted
技术标签:
【中文标题】选择 AS 在 interbase 中不工作【英文标题】:Select AS not working in interbase 【发布时间】:2011-02-18 13:52:46 【问题描述】:作品
select payeeid, EXTRACT(WEEKDAY FROM checkdate) as DOW,
(bankcleared - checkdate) as DateDiff
from Master
where (bankcleared is not null)
order by payeeid, DOW, DateDiff
将DateDiff
添加到Where
- 不起作用
select payeeid, EXTRACT(WEEKDAY FROM checkdate) as DOW,
(bankcleared - checkdate) as DateDiff
from Master
where (bankcleared is not null) AND (DateDiff >= 1)
order by payeeid, DOW, DateDiff
【问题讨论】:
对不起,我也想问....为什么将 DateDiff 添加到 where 会导致错误 - DateDiff Column unknown 因为 DATEDIFF 是一个内置函数,它检索两个日期时间戳之间的日期部分差异。 【参考方案1】:您只能在 GROUP BY、ORDER BY 或 HAVING 子句中使用列别名。
标准 SQL 不允许您在 WHERE 子句中引用列别名。施加此限制是因为在执行 WHERE 代码时,可能尚未确定列值。
试试这个
select payeeid, EXTRACT(WEEKDAY FROM checkdate) as DOW,
(bankcleared - checkdate) as DateDiff
from Master
where (bankcleared is not null) AND ((bankcleared - checkdate)>= 1)
order by payeeid, DOW, DateDiff
有关更多信息,请访问这些链接
Can you use an alias in the WHERE clause in mysql?
Unknown Column In Where Clause
【讨论】:
【参考方案2】:select payeeid,
EXTRACT(WEEKDAY FROM checkdate) as DOW,
(bankcleared - checkdate) as DateDiff
from Master
WHERE (bankcleared is not null)
AND ((bankcleared - checkdate)>= 1)
Order by payeeid, DOW, DateDiff
【讨论】:
以上是关于选择 AS 在 interbase 中不工作的主要内容,如果未能解决你的问题,请参考以下文章
Interbase 错误:SQLDA 缺失或版本不正确,或者变量的数量/类型不正确