SQL ORACLE QUERY中的视图

时间:2014-04-16 10:43:41

标签: sql oracle sqlplus database

TABLE DESC:

Product (Prodid, Prodesc, Price, Stock)
Sales (Saleid, Proid, qty, custname) 

QUERY:

Create a view which displays Proid, Prodesc and sum of quantity in sales.  

我曾多次尝试创建视图但导致出现错误,例如NOT SINGLE GROUP FUNCTION,而不是GROUP BY EXPRESSION。解决方案请。

错误:

a)NOT GROUP BY:

create or replace view sale_vs as select * from(select prodesc,proid,sum(qt
y) from sales,product group by proid);

b)不是单一群体:

create or replace view sale_vs as select product.prodid,product.prodesc,sum
(qty) from product,sales where sales.proid=product.prodid;

1 个答案:

答案 0 :(得分:1)

尝试此查询: -

create or replace view myView as
select p.Prodid Product_ID, p.Prodesc Product_description, sum(s.qty) Sum_of_qty
from product p, sales s where p.Prodid= s.Proid group by p.prodid, p.prodesc 

这是sqlfiddle http://www.sqlfiddle.com/#!4/02820/2