我需要创建一个这样的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;
谢谢!
答案 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 ...