title: node.js - Using SQL variables in js query string
body: <p>So, I am selecting entries from a table and grouping them, but also want to create an index column in the result. Executing this query in MySQL Workbench works, but when I try to execute it on the node.js server there is a parse error and mysql says that the syntax is incorrect.  </p>
  
  <p>I am using a <strong>raw</strong> query and <strong>QueryChainer</strong> from <strong>sequelize</strong>.</p>
  
  <pre><code>SET @cnt = 0;
  SELECT (@cnt := @cnt + 1) AS id, et.fileName, et.creationDate,
    SUM(COALESCE(et.amountExported, 0)) AS sumExported, 
    SUM(COALESCE(et.amountImported, 0)) AS sumImported,
    (SUM(COALESCE(et.amountExported, 0)) - SUM(COALESCE(et.amountImported, 0))) AS difference
  FROM exported_transactions AS et
  WHERE (et.creationDate BETWEEN ? AND ?) /* ? is replaced by a date string */
  GROUP BY et.fileName
  </code></pre>
  
  <p>Removing the variable in the sql query and executing it on the node.js server works fine:</p>
  
  <pre><code>SELECT et.fileName, et.creationDate,
    SUM(COALESCE(et.amountExported, 0)) AS sumExported, 
    SUM(COALESCE(et.amountImported, 0)) AS sumImported,
    (SUM(COALESCE(et.amountExported, 0)) - SUM(COALESCE(et.amountImported, 0))) AS difference
  FROM exported_transactions AS et
  WHERE (et.creationDate BETWEEN ? AND ?) /* ? is replaced by a date string */
  GROUP BY et.fileName
  </code></pre>
  
  <p>Of course, I can do just fine without the "id" column, but I want it there for sorting. Is there a solution to my problem or is there some other way to generate this auto incremented column?</p>