使用等式作为视图创建的一部分
Using equation as part of view creation
当我尝试这个时,出现语法错误,但不确定我的方法是否有误。我正在尝试将标志添加到 table 以识别某些记录
Create view
as
SELECT
col1 * 0.5 / col2 as value_per_sqm,
col3 / col2 as other_value,
(col1 * 0.5 / col2) < (col3 / col2) as higher
哪个returns;
ERROR: syntax error at or near "("
调整以上我可以看到我可以 运行 一个布尔值,如果我不使用方程并且前两个方程有效,则返回 true。我试过了;
Create view
as
SELECT
col1 * 0.5 / col2 as value_per_sqm,
col3 / col2 as other_value,
(value_per_sqm) < other_value) as higher
但它无法查询该列,因为它尚未创建。
感谢任何帮助
为您提供帮助:
create view yourview
as
SELECT value_per_sqm,
other_value,
(value_per_sqm < other_value) as higher
FROM
(SELECT col1 * 0.5 / col2 as value_per_sqm,
col3 / col2 as other_value FROM yourtable) subQ;
当我尝试这个时,出现语法错误,但不确定我的方法是否有误。我正在尝试将标志添加到 table 以识别某些记录
Create view
as
SELECT
col1 * 0.5 / col2 as value_per_sqm,
col3 / col2 as other_value,
(col1 * 0.5 / col2) < (col3 / col2) as higher
哪个returns;
ERROR: syntax error at or near "("
调整以上我可以看到我可以 运行 一个布尔值,如果我不使用方程并且前两个方程有效,则返回 true。我试过了;
Create view
as
SELECT
col1 * 0.5 / col2 as value_per_sqm,
col3 / col2 as other_value,
(value_per_sqm) < other_value) as higher
但它无法查询该列,因为它尚未创建。
感谢任何帮助
为您提供帮助:
create view yourview
as
SELECT value_per_sqm,
other_value,
(value_per_sqm < other_value) as higher
FROM
(SELECT col1 * 0.5 / col2 as value_per_sqm,
col3 / col2 as other_value FROM yourtable) subQ;