如何在mysql视图中引用刚刚创建的列?

时间:2014-06-18 07:00:01

标签: mysql view reference

我需要创建一个这样的mysql视图:

第二列是从第一个视图列计算的。如何引用第一列名称来定义第二列?

create view v_data
as select
   ..... AS 'first_view_column',
   (here can I reference 'first_view_column' directly and how to ?)*20 AS 'second_view_column'
from tb;

谢谢!

2 个答案:

答案 0 :(得分:0)

您只需使用常规SELECT语法:

CREATE VIEW v_data AS
 SELECT col1, (COL1*20) AS col2
  FROM tb;

答案 1 :(得分:0)

您可以使用(SELECT first_colum_alias)

SELECT ... AS first, other+(SELECT first)
FROM ...