I want to make a query to list cats that took longer than average cats to sell? I have five tables:
Animal, Sale, AnimalOrderItem, AnimalOrder, and SaleAnimal
Animal table: AnimalID, Name, Category (cat, dog, fish)
SaleAnimal table: SaleID, AnimalID, SalePrice
Sale table: SaleID, date, employeeID, CustomerID
AnimalOrderItem table: OrderID, AnimalID, cost
AnimalOrder: OrderID, OrderDate, ReceivingDate, SupplierID, ShippingCost, EmployeeID
There is other tables I don’t think they have an effect on the query.
I thought of the following ... make a query to calculate days to sell for all ex.:
[SaleDate]-[ReceiveDate] AS DaysToSell
Have the INNER JOIN built:
Sale INNER JOIN ((AnimalOrder INNER JOIN (Animal INNER JOIN AnimalOrderItem
ON Animal.AnimalID = AnimalOrderItem.AnimalID) ON AnimalOrder.
OrderID = AnimalOrderItem.OrderID) INNER JOIN SaleAnimal ON Animal.
AnimalID = SaleAnimal.AnimalID) ON Sale.SaleID = SaleAnimal.SaleID
Create another query based on the above query
SELECT AnimalID, Name, Category, DaysToSell
WHERE Category="Cat" AND DaysToSell>
(SELECT Avg(DaysToSell)
FROM the earlier query
WHERE Category="Cat"
ORDER BY DaysToSell DESC;
After running the query it I got error saying
ORA-00921: unexpected end of SQL command
Any suggestions! please