选择AS不在interbase中工作

时间:2011-02-18 13:52:47

标签: sql delphi interbase

作品

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  

2 个答案:

答案 0 :(得分:11)

您只能在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

答案 1 :(得分:0)

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