Mekhala Mekhala - 7 months ago 19
SQL Question

use of COUNT to count the number of times the product has been ordered

I am trying to use COUNT to well count the number of times a product has been ordered.

Below is what I have,which is not working out. I get the error


SQL Error: ORA-00937: not a single-group group function


When I try to use the Group by function it said it's not a GROUP by function or that it cannot be used.

CREATE OR REPLACE VIEW product_summary AS
SELECT product_name, COUNT(*) AS order_count, item_total AS order_total
FROM order_item_products

Answer

I think the error is pretty clear. Add group by:

CREATE OR REPLACE VIEW product_summary AS
    SELECT product_name, COUNT(*) AS order_count,
           SUM(item_total) AS order_total
    FROM order_item_products
    GROUP BY product_name;
Comments