title: How to join table with condition available table
body: <p>In mysql, I have some tables :</p>
  <ul>
  <li>a_202005</li>
  <li>a_202004</li>
  <li>a_202003</li>
  </ul>
  <p>2020 = year, last 2 digits as month.</p>
  <p>in those table, for example in table a_202005, fields are:</p>
  <pre><code>/*  date         total
      2020-05-01   100000
      2020-05-01   200000
      2020-05-02   150000
      ....
      .....
      2020-05-31   300000  */
  </code></pre>
  <p>the problem is, i want show something like this:</p>
  <pre><code>/* year    month  grand_total
         
  // 2020    05     1500000
      
  // 2020    04     2000000
       
  // 2020    03     3500000   */
  </code></pre>
  <ul>
  <li>year = available year in every table like 'a_'</li>
  <li>month = available month in every table like 'a_'</li>
  <li>grand_total=sum(total) in every table.</li>
  </ul>
  <p>My query to get year and month available:</p>
  <pre><code>select mid(table_name,3,4) as year, right(table_name,2) as month
  from information_schema.tables
  where table_name like 'a_' 
  order by year desc, month desc;
  </code></pre>
  <p>this is my query  to get total from every table:</p>
  <pre><code>select sum(total) as grand_total from a_202005
  </code></pre>
  <p>but I confuse how to get the table that I want, thanks before.</p>