title: MariaDB SELECT all records for only accounts expiring within 30 days
body: <p>How do I <em>only</em> <code>SELECT</code> records using MariaDB whose accounts are set to expire in 30 days based off of the <code>max()</code> expiration date?</p>
  
  <p><strong>What <em>not</em> to <code>SELECT</code></strong>: if today is December 7, 2017 and below the account "a" has a maximum expiration date of June 1st of 2018 then absolutely no records should be returned for account "a" with the desired <code>SELECT</code> query regardless of the fact that this table <em>also</em> contains rows for account "a" that are older than today's date.</p>
  
  <p><strong>What <em>should</em> be selected:</strong> account "b" has two records and it's <code>max()</code> record is less than 30 days; the row <code>id</code> 4 is what row <em>should</em> be returned from the desired <code>SELECT</code> query.</p>
  
  <pre><code>+----+---------+------------+
  | id | account | expiration |
  +----+---------+------------+
  | 1  | a       | 2017-01-01 |
  | 2  | a       | 2018-06-01 |
  | 3  | b       | 2017-01-01 |
  | 4  | b       | 2018-01-01 |
  +----+---------+------------+
  </code></pre>
  
  <p>I've spent a bit of time on this in various aspects though my most rigorous testing ultimately fails. Here is one bit that I've got working:</p>
  
  <pre><code>SELECT DATEDIFF(STR_TO_DATE(expiration, '%Y-%m-%d'),CURDATE()) AS days_left FROM table;
  </code></pre>