【发布时间】:2015-01-08 23:44:04
【问题描述】:
你好亲爱的堆栈溢出朋友,
我想使用位于另一个视图中的单个字段作为 WHERE 子句的参数(在另一个视图中)。但是,我找不到完成这项工作的正确方法。
我已经使用了 FIRST() 函数,但这会产生语法错误。
这可能与它选择整个第一行的事实有关,但我只想获得这一行中的一个字段。 (其实整个view只有一个字段)
/*this first view contains the value to use for the second view, called average */
CREATE OR REPLACE VIEW getAverage AS
SELECT AVG(todoitem.completiondate-todoitem.creationdate) as average from todolist
inner join todoitem on todoitem.id=todolist.id;
/*this view has a WHERE clause that should use a value in the getAverage VIEW */
CREATE OR REPLACE VIEW aboveAverage AS
SELECT * FROM todolist
inner join todoitem on todoitem.id=todolist.id
WHERE (todoitem.completiondate-todoitem.creationdate > FIRST(getAverage.average));
如果有人可以帮助我,我将非常感激。
【问题讨论】: