使用clickhouse创建视图时报错
SQL 错误 [47]: ClickHouse exception, code: 47, host: localhost, port: 8123; Code: 47, e.displayText() = DB::Exception: Missing columns:xxx required columns: yyy
因为多张表内有相同名称的字段,所以在创建视图时的子查询里用到了别名,其实SQL语句在直接运行查询时是可以正常运行的,
例如 :
--查询可以正常执行 SELECT A.ID AS AID,B.ID AS BID FROM TA AS A INNER JOIN TB AS B ON 1=1 --创建视图报错 CREATE VIEW V_TEST AS SELECT A.ID AS AID,B.ID AS BID FROM TA AS A INNER JOIN TB AS B ON 1=1
查找官网文档中CREATE VIEW中没找到特殊的说明,只是在查询相关的文档中找到两个地方对别名的提示,抱着试试看的态度对语句进行了修改
--修改后的SQL CREATE VIEW V_TEST AS SELECT AID,BID FROM (SELECT ID AS AID FROM TA) AS A INNER JOIN (SELECT ID AS BID FROM TB) AS B ON 1=1
如有错误,请留言改正