title: Create MySQL view with an extra calculated field in table
body: <p>I am using python and MySQLdb module. I have a table that looks like this;</p>
  
  <pre><code>TableA
  ------
  id
  latest_time_seen
  </code></pre>
  
  <p>The format of <code>latest_time_seen</code> is <code>2014-02-05 00:00:50</code></p>
  
  <p>From <code>TableA</code>, I would like to create a view on mysql that is similar to <code>TableA</code> and the only difference is that it contains an extra calculated field called <code>secs_diff</code>.</p>
  
  <p><code>secs_diff</code> is equal to the number of seconds difference between current time and <code>latest_time_seen</code>.</p>
  
  <p>The output table will look something like this;</p>
  
  <pre><code>OutputTable
  -----------
  id
  latest_time_seen
  secs_diff
  </code></pre>
  
  <p>I doubt if I have problems writing a python function to calculate secs_diff. But I am stuck at how to integrate this function into a MySQL query that generates a view that looks like <code>OutputTable</code>.</p>
  
  <p>How can such a view be generated using python and MySQLdb module? Or would it be better to use a temporary table? It will be better if such a view can be generated purely from a MySQL query. But I am not sure if MySQL query is flexible enough to calculate the time difference.</p>
  
  <p>Thank you very much.</p>