title: Window Functions and effiecient querying
body: <p>I am looking for certain information from canceled transactions...</p>
  
  <pre><code>What was the Next Transaction from that Canceled Transaction's Store 
  What was the Next Transaction from that Canceled Transaction's Customer'
  What was the Next Transaction from that Canceled Transaction's City
  and so on and so forth...
  </code></pre>
  
  <p>I have millions and millions of Transactions
  but only about 100,000 Canceled Transactions</p>
  
  <p>Window Functions work great with this  as I use the LEAD() function and partition it by Store, Customer, City etc...</p>
  
  <p>but I need to apply these Window functions to every Transaction (as Window functions only work with your result set)
  then I have to filter all these Transactions and get (the info for) only my Canceled Transactions.</p>
  
  <p>If I just bring in my Canceled Transactions and query for this Data (of temp tables)  - The Query seems less efficient and takes longer.</p>
  
  <p>It seems however I do it the Window Functions perform better.</p>
  
  <p>Is there a better way to do this then to apply Window Functions to ALL of my Transactions?  (then filtering for the Canceled ones) </p>