title: Changing Query to work for all instances in a database table
body: <p>I'm currently working on calculating markouts for some post trade analysis. In short, a markout is the change between prices over a time interval.</p>
  
  <p>I have two tables, <code>FILLORDERACK</code> and <code>NBBO_20181001</code>.</p>
  
  <p><code>FILLORDERACK</code> contains the following columns:</p>
  
  <p><code>BIDPX, OFFERPX, TRANSACTTIME, TRADEDATE, SYMBOL</code></p>
  
  <p><code>NBBO_20181001</code> contains the following columns:</p>
  
  <p><code>BID, ASK, SYMBOL, TS</code></p>
  
  <p>The data in <code>NBBO_20181001</code> is a few million records of bid and offer prices for stocks in millisecond intervals.</p>
  
  <p>What my query currently does it take a symbol and calculate the price markout at 1000 milliseconds after the trade:</p>
  
  <p>i.e: Get the midpoint of the prices from <code>FILLORDERACK</code>, divide it by the midpoint of the prices at the closest <code>TS</code> from <code>NBBO_20181001</code>, and subtract 1 from the value.</p>
  
  <p>I currently have it working but for only 1 specific occurrence where <code>t2.symbol = 'F'</code>.</p>
  
  <p>I'm unsure how to append my query to work for all occurrences of a given symbol in the <code>F</code> from <code>FILLORDERACK</code>. If I have 200 rows in this table for that symbol, I should have 200 markouts calculated in the results. </p>
  
  <pre><code>select (((t2.BIDPX + t2.OFFERPX) / 2) / ((t1.BID + t1.ASK) / 2)) - 1, t2.TRANSACTTIME
  from NBBO_20181001 t1, FILLORDERACK t2
  where t2.symbol = 'F' and t1.symbol = t2.symbol and t2.TRADEDATE = '20181001'
  and t1.TS between t2.TRANSACTTIME and TIMESTAMPADD(SQL_TSI_ms, 1000, (t2.TRANSACTTIME))
  order by t1.TS desc limit 1
  </code></pre>