title: mysql select an average from order by with a query
body: <p>I have 2 tables "recipes", "recipes_items" , in the table recipes_items i have an  integer columns "important". Now I have a query that pulls the recipes ordered by the sum(important) of the <code>recipes_items.important</code> , the order by  have a sub query : </p>
  
  <pre><code>(SELECT sum(...) from recipes_items...) DESC)
  </code></pre>
  
  <p>BUT what I want is to retrieve as additional column in the recipes query the average of the column "important" from table recipes_items
  How can that be ?</p>
  
  <p>Thanks
  Moshe</p>
  
  <pre><code>select  recipes.recipeName,
          recipes.recipeID,
          AVG (recipes_items.importance) AS averageScore
      from  recipes,recipes_items
      WHERE  recipes_items.recipeID=recipes.recipeID
      ORDER BY  
        ( SELECT  SUM(recipes_items.importance) AS sumImportance
              FROM  recipes_items
              WHERE  recipes_items.recipeID = recipes.recipeID
                AND  recipes_items.itemID IN ('1059')
        ) DESC
      LIMIT  20
  </code></pre>
  
  <p>What i would like to get in results is order by the importance column from recipes_items.itemID that are matching a set of ID's in the 'IN()' section, also wanted to have the number or sum of the matching ID's in each row of a matching ID's to the <code>recipes_items.itemID</code>...</p>