试图从另一个视图创建一个视图? Oracle顶点

我有一个尝试已经解决了一段时间的作业,但我做不到

第一个问题是“ 1.创建一个视图VE1,其中将显示customer_id,cust_title和每个客户的总金额。” 所以我创建了第一个视图

 CREATE OR REPLACE FORCE VIEW "VE_1" ("CUST_ID","CUST_TITLE","TOTAL_AMOUNT") AS 
  SELECT Customer.cust_id,customer.cust_title,SUM(lead.amount) AS Total_amount
FROM customer,lead
WHERE customer.cust_id=lead.cust_id
GROUP BY customer.cust_id,customer.cust_title
ORDER BY customer.cust_id
/

因此,在创建视图后(我不确定这是否是正确的答案)。这个问题二是我发布这个问题的主要原因 “您想要与1中相同的组结果,但仅针对总金额超过25,000(HAVING)的客户。您可以使用VE1中的连续视图VE2来执行此操作吗?查看VE3”。 所以我尝试了这段代码

CREATE OR REPLACE FORCE VIEW "VE_2" ("CUST_ID","TOTAL_AMOUNT") AS 
  SELECT VE_1.cust_id,VE_1.cust_title,SUM(lead.amount) AS Total_amount
FROM VE_2
WHERE customer.cust_id=lead.cust_id
GROUP BY customer.cust_id,customer.cust_title
HAVING
    count( amount ) > 25000
ORDER BY customer.cust_id
/

并说“编译失败,第0行(17:14:40) ORA-01731:遇到了圆形视图定义”

请帮助!

okgame 回答:试图从另一个视图创建一个视图? Oracle顶点

您收到错误,因为您试图从即将创建的视图中进行选择。另外,您引用copy_list(_,[]). copy_list(L,N,R) :- N > 0,N1 is N-1,copy_list(L,N1,R2),append(L,R2,R).子句中未介绍的customerlead。所以那也必须失败。

您几乎可以将所有语句重用于第一个视图,以获取第二个视图。只需添加一个FROM子句即可。

HAVING

您还可以使用第一个视图创建第二个视图。但是在这里,您需要使用CREATE OR REPLACE VIEW ve_2 (cust_id,cust_title,total_amount) AS SELECT customer.cust_id,customer.cust_title,sum(lead.amount) AS total_amount FROM customer INNER JOIN lead ON customer.cust_id = lead.cust_id GROUP BY customer.cust_id,customer.cust_title HAVING sum(lead.amount) > 25000; 子句来代替HAVING子句,因为数据已经聚合。

WHERE
本文链接:https://www.f2er.com/2917645.html

大家都在问