Question

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.  

I ve tried many times creating the view but lead to an error like NOT SINGLE GROUP FUNCTION,NOT A GROUP BY EXPRESSION. Solution Please.

ERRORS:

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) NOT SINGLE GROUP:

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

Solution

Try this query:-

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 

Here's the sqlfiddle http://www.sqlfiddle.com/#!4/02820/2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top