Note that there are some explanatory texts on larger screens.

plurals
  1. POMYSQL: Retrieve latest unique records
    primarykey
    data
    text
    <p>I have a table that logs rows where the member_id repeats.</p> <h2>The column fields are:</h2> <p><strong>id:</strong> int(7) Primary key, Auto increment <br/> <strong>member_id:</strong> int(7) Index <br/> <strong>item_qt:</strong> int(7) <br/></p> <pre><code>+----+-----------+---------+----------+ | id | member_id | item_qt |timestamp | +----+-----------+---------+----------+ |553 | 107 | 10 | 00:17:53 | +----+-----------+---------+----------+ |552 | 107 | 25 | 00:17:51 | +----+-----------+---------+----------+ |551 | 122 | 6 | 00:17:43 | +----+-----------+---------+----------+ |550 | 122 | 9 | 00:17:22 | +----+-----------+---------+----------+ |549 | 107 | 19 | 00:17:11 | +----+-----------+---------+----------+ </code></pre> <p><br /><br /></p> <h2>First, <strong>what query would retrieve these results?</strong></h2> <ul> <li>select the latest unique rows</li> </ul> <p>(This post gave me some direction) <a href="https://stackoverflow.com/questions/1227619/retrieve-last-latest-distinct-highest-value"><a href="https://stackoverflow.com/questions/1227619/retrieve-last-latest-distinct-highest-value">Retrieve last (latest) distinct highest value</a></a></p> <pre><code>+----+-----------+---------+----------+ | id | member_id | item_qt |timestamp | +----+-----------+---------+----------+ |553 | 107 | 10 | 00:17:53 | +----+-----------+---------+----------+ |551 | 122 | 6 | 00:17:43 | +----+-----------+---------+----------+ </code></pre> <p><br /><br /></p> <h2>Next, <strong>How do you get this?</strong></h2> <pre><code>+----+-----------+---------+----------+-------------+ | id | member_id | item_qt |timestamp | item_qt_sum | +----+-----------+---------+----------+-------------+ |553 | 107 | 10 | 00:17:53 | 54 | +----+-----------+---------+----------+-------------+ |551 | 122 | 6 | 00:17:43 | 15 | +----+-----------+---------+----------+-------------+ </code></pre> <ul> <li>sum the item_qt for a number of rows in &lt; 5 minutes time</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload