title: How to get kqy value pairs into MySQL variable?
body: <p>I am trying to create kind of a quality score for star ratings from different merchants. E.g. ebay, amazon. Running on MySQL 5.7.x</p>
  <p>The table looks like this:</p>
  <pre><code>article_id | merchant_id | rating | ratings
  123          1             5        120
  124          2             4.5      29
  </code></pre>
  <p>Now the prodblem is that each merchant has a different amount of ratings. Amazon receives many more ratings then a small site. So there must be kind of a waighted average to reflect that. I am trying to determine if the rating on a page is a good and strong indication of a product quality.</p>
  <p>The idea now is to get the avg amount of ratings per merchant first:</p>
  <pre><code>SET @ratings_avg = (SELECT avg(ratings)
  FROM products
  WHERE MERCHANT_ID = 2
  AND ratings IS NOT NULL
  AND ratings &gt; 0);
  </code></pre>
  <p>Then calculate a quality with a waighted average from ratings_avg</p>
  <pre><code> SELECT
     MERCHANT_ID,
     ARTICLE_ID,
     IF(RATINGS&gt;0, 1.0865*LN(RATINGS), 0) * @ratings_avg 
   FROM products
  </code></pre>
  <p>This does not work as I would need a key value pair of ratings_avg and merchant_id. How could that be done?</p>