title: Use MySQL variables with Sequelize
body: <p>I am trying to grab max of 4 rows for each distinct value. This query I have works.  </p>
  
  <p><code>SET @currcount = NULL, @currvalue = NULL;
  SELECT * FROM (
      SELECT
          *, 
          @currcount := IF(@currvalue = quantity, @currcount + 1, 1) AS rank,
          @currvalue := quantity AS whatever
      FROM wines
      where restaurant_id = 16 and owner_id is null 
      ORDER BY quantity DESC
  ) AS x WHERE rank &lt;= 4</code></p>
  
  <p>But now I can't get it to work with Sequelize. Can I use @variable in Sequelize?</p>
  
  <p>Has anyone done this? Or am I going to have to just use a raw query?</p>
  
  <p>Thanks! </p>