I have little problem with my SQL query. I want to get my CUSTOMERS table id, name, surname, and all money they spent on my shop i've created.
SELECT o.CUSTOMER_ID AS "ID", c.name AS "Name", c.SURNAME AS "Surname",
(SELECT op.AMOUNT * p.PRICE
FROM PRODUCTS p
WHERE p.id = op.PRODUCT_ID) AS "Money spent"
FROM ORDERS o
LEFT JOIN CUSTOMERS c ON c.ID = o.CUSTOMER_ID
LEFT JOIN ORDERS_PRODUCTS op ON op.ORDER_ID = o.id
GROUP BY o.CUSTOMER_ID;
And i have error message like this:
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
*Cause:
*Action:
Error at Line: 1 Column: 31
I have to say, that i have to use GroupBy clause, because i have this in my school project requirements. And this is my base diagram, if it could help you. http://i61.tinypic.com/2d1okut.jpg