title: SQL - CTE vs VIEW
body: <p>My question here is what is the difference between <code>CTE</code> and <code>View</code> in <strong>SQL</strong>. I mean in which case I should use the <code>CTE</code> and which case the <code>View</code>. I know that both are some kind of virtual tables but I can't differentiate their use.</p>
  
  <p>I found a similar question <a href="https://stackoverflow.com/questions/6026842/cte-vs-view-performance-in-sql-server">here</a> but it's about performance.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>For example: I have a database filled with trades(<code>tbl_trade</code>). I need to select from 3.5 millions records only the trades that was opened the current month until current time and then manipulate the data(with different queries on the virtual table - this looks like View). The problem here is that I want a <code>SUM</code> of 3-4 columns and then on I need to <code>SUM</code> some columns  and create a virtual column with the result(looks like CTE).</p>
  
  <p>Eg: <code>tbl_trade</code> has columns: <code>profit</code>,<code>bonus</code> and <code>expenses</code>.
  I need <code>SUM(profit)</code>,<code>SUM(bonus)</code>,<code>SUM(expenses)</code> and a new column <code>total</code> which will be equal to <code>SUM(profit)</code>+<code>SUM(bonus)</code>+<code>SUM(expenses)</code>.</p>
  
  <p>PS. Rerunning the queries for <code>SUM</code> is not an option since I already have the result.</p>
  
  <p>Thanks in advance!</p>