I am working on a mock database for a school project and I have two tables: CUSTOMERS AND ORDERS Both tables look like this
CUSTOMERS: custID, custLName, custFName, custAddress, custTown, custPostcode, custPhone, custEmail
And
ORDERS: orderID, orderDate, dispatchDate, custID (foreign key)
I am trying to generate a query that returns the full name and phone number of the customer who has made the most orders. This is my query below however it is returning an error on the GROUP BY function stating ORA-00904: "CUSTOMER": invalid identifier
SELECT b.custFName || ' ' || b.custLName || ', ' || b.custPhone AS Customer,
COUNT(DISTINCT o.custID) AS Orders_Placed
FROM CUSTOMERS b, ORDERS o
GROUP BY Customer
HAVING COUNT(DISTINCT o.custID) AND b.custID = o.custID
ORDER BY o.custID DESC;