title: division by zero error while calculating growth percentage from two different tables
body: <p>The table I currently have looks like this: (data comes from two different tables, 19921231, 19930331)
  <a href="https://i.stack.imgur.com/ol3XV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ol3XV.png" alt="enter image description here" /></a></p>
  <p>The table I want to create looks like this (5th column added)
  <a href="https://i.stack.imgur.com/HkGhV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HkGhV.png" alt="enter image description here" /></a></p>
  <p>Goal: determine the deposit growth rate at each bank. I.e. Comparing the amount of deposits held at a bank in the previous quarter (e.g. 19921231) to the deposits of the most recent quarter (e.g. 19930331). Then view the increase/decrease as a percentage.</p>
  <p>This is the code I have written so far:</p>
  <pre><code>select 
  AL.repdte as `Date`, AL.cert, AL.name, AL.dep as `Deposits`
  FROM usa_fdic_call_reports_1992.All_Reports_19921231_Assets_and_Liabilities as AL
  
  UNION ALL
  
  select 
  AL.repdte as `Date`, AL.cert, AL.name, AL.dep as `Deposits`
  FROM usa_fdic_call_reports_1993.All_Reports_19930331_Assets_and_Liabilities as AL
  
  </code></pre>
  <p>An answer to this question suggested this code, that works However, for some reason I getting an output of &quot;NULL&quot;</p>
  <pre><code>select al19930331.repdte as `Date`, al19930331.cert, al19930331.name,
         al19930331.dep as Deposits_1993,
         al19921231.dep as Deposits_1992,
         (al19930331.dep - al19921231.dep) / al19921231.dep as grow_rate
  from usa_fdic_call_reports_1993.All_Reports_19930331_Assets_and_Liabilities as al19930331 left join
       usa_fdic_call_reports_1992.All_Reports_19921231_Assets_and_Liabilities as al19921231
       on al19930331.cert = al19921231.cert and
          al19930331.name = al19921231.name and
          al19921231.repdte = date_add(al19930331.repdte, interval 1 year);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/8QAdk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8QAdk.png" alt="enter image description here" /></a></p>
  <p>In an attempt to isolate the &quot;NULL&quot; issue, I was able to eliminate the &quot;NULL&quot; issue. I did so by  simplyfing the query. It worked I was able to view both quarters of &quot;deposits&quot;.</p>
  <pre><code>select al19930331.repdte as `Date`, al19930331.cert, al19930331.name,
         al19930331.dep as Deposits_1993,
         al19921231.dep as Deposits_1992,
         (al19930331.dep - al19921231.dep) / al19921231.dep as grow_rate
  from usa_fdic_call_reports_1993.All_Reports_19930331_Assets_and_Liabilities as al19930331 left join
       usa_fdic_call_reports_1992.All_Reports_19921231_Assets_and_Liabilities as al19921231
       on al19930331.cert = al19921231.cert and
          al19930331.name = al19921231.name
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DkAkY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DkAkY.png" alt="enter image description here" /></a></p>
  <p>Once I determined that there didn't seem to be any problem with retrieving the deposit data from the last two quarters, I decided to remove  the last line of this code:</p>
  <pre><code>select al19930331.repdte as `Date`, al19930331.cert, al19930331.name,
         al19930331.dep as Deposits_1993,
         al19921231.dep as Deposits_1992,
         (al19930331.dep - al19921231.dep) / al19921231.dep as grow_rate
  from usa_fdic_call_reports_1993.All_Reports_19930331_Assets_and_Liabilities as al19930331 left join
       usa_fdic_call_reports_1992.All_Reports_19921231_Assets_and_Liabilities as al19921231
       on al19930331.cert = al19921231.cert and
          al19930331.name = al19921231.name and
          al19921231.repdte = date_add(al19930331.repdte, interval 1 year);
  </code></pre>
  <p>To this:</p>
  <pre><code>select al19930331.repdte as `Date`, al19930331.cert, al19930331.name,
         al19930331.dep as Deposits_1993,
         al19921231.dep as Deposits_1992,
         (al19930331.dep - al19921231.dep) / al19921231.dep as grow_rate
  from usa_fdic_call_reports_1993.All_Reports_19930331_Assets_and_Liabilities as al19930331 left join
       usa_fdic_call_reports_1992.All_Reports_19921231_Assets_and_Liabilities as al19921231
       on al19930331.cert = al19921231.cert and
          al19930331.name = al19921231.name
  </code></pre>
  <p>This worked, sort of, however it exposed a &quot;division by zero&quot; error.   So now the question is how can add back a solution to eliminate the division by error, that would enable me to add the last line of code back?</p>