我之前创建了2个视图,如下所示:
CREATE VIEW T22
AS
(SELECT anumber, AVG(slevel)
FROM SPOSSESSED
GROUP BY anumber);
CREATE VIEW T23 (anumber, slevel)
AS
(SELECT anumber, 0
FROM APPLICANT
WHERE anumber NOT IN (SELECT anumber FROM SPOSSESSED));
现在,我需要CREATE VIEW,它是上述两个视图的UNION。我尝试了这个完全正常的语句并显示了我想要的结果:
SELECT *
FROM T22
UNION
SELECT *
FROM T23;
但是当我尝试为此创建一个视图时,它有一个我似乎无法识别的语法错误:
CREATE VIEW T24
AS
(SELECT *
FROM T22
UNION
SELECT *
FROM T23);
答案 0 :(得分:1)
管理我自己解决问题,opps!
解决方案是删除括号,语法错误消失了:
CREATE VIEW T24 AS SELECT* FROM T22 UNION SELECT * FROM T23;
答案 1 :(得分:0)
列的命名方案存在冲突,在这种情况下您无法使用SELECT *
。但是,您可以更改anumber
并将其别名更改为其他名称。解决问题。
类似的东西:
CREATE VIEW T24
AS
(
SELECT anumber AS anumber1,
AVG(slevel)
FROM T22
UNION
SELECT anumber,
slevel
FROM T23
);
答案 2 :(得分:0)
表t22和表t23中的数据类型是否匹配? 列数是否匹配? 请发布您收到的错误。