title: Combining multiple SQL Queries
body: <p>I want to make a query to list cats that took longer than average cats to sell?
  I have five tables:</p>
  
  <p>Animal, Sale, AnimalOrderItem, AnimalOrder, and SaleAnimal</p>
  
  <blockquote>
    <p>Animal table: AnimalID, Name, Category
    (cat, dog, fish)</p>
    
    <p>SaleAnimal table: SaleID, AnimalID,
    SalePrice</p>
    
    <p>Sale table: SaleID, date, employeeID,
    CustomerID</p>
    
    <p>AnimalOrderItem table: OrderID,
    AnimalID, cost</p>
    
    <p>AnimalOrder: OrderID, OrderDate,
    ReceivingDate,
         SupplierID, ShippingCost, EmployeeID</p>
  </blockquote>
  
  <p>There is other tables I don’t think they have an effect on the query.</p>
  
  <p>I thought of the following ... make a query to calculate days to sell for all ex.:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>Create another query based on the above query </p>
  
  <pre><code>SELECT AnimalID, Name, Category, DaysToSell
  WHERE Category="Cat" AND DaysToSell&gt;
  (SELECT Avg(DaysToSell)
  FROM the earlier query
  WHERE Category="Cat"
  ORDER BY DaysToSell DESC;
  </code></pre>
  
  <p>After running the query it I got error saying</p>
  
  <blockquote>
    <p>ORA-00921: unexpected end of SQL
    command</p>
  </blockquote>
  
  <p>Any suggestions! please</p>