Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL: Query to compare succesive values
    primarykey
    data
    text
    <p>I have a table like this:</p> <pre><code>| Time | Cash | Employee | |----------------|----------| | 03:30 | 300 | McClane | | 03:35 | 400 | Travis | | 04:30 | 200 | Travis | | 04:53 | 100 | John | </code></pre> <p>I need to select 2 consecutive values that: </p> <ul> <li>results in >= 500 (cash) </li> <li>both are in less than 1 minute (time) from each other </li> <li>are by the same Employee</li> </ul> <p>It should be like this:</p> <pre><code>| Time | Cash | Employee | |----------------|----------| | 03:35 | 400 | Travis | | 04:30 | 200 | Travis | </code></pre> <p>The closest thing I've achieved is something like this:</p> <pre><code>select time, cash, employee from table where (Cash + Cash) &gt;= 500 </code></pre> <p>and</p> <pre><code>select time(now() - interval 1 minute) </code></pre> <p>This can give me the - 1 minute but I can't use the "Time" field instead of the "now()" function.</p> <p>Thanks in advance for any help and sorry for the broken english.</p> <p><strong>EDIT.</strong> A big mistake, it doesn't matter if the the records are not successive, so I can order them by time first.</p> <p>I need to print the records like this:</p> <pre><code>| Time | Cash | Employee | |----------------|----------| | 03:35 | 400 | Travis | | 04:30 | 200 | Travis | | Time | Cash | Employee | |----------------|----------| | 05:00 | 300 | John | | 05:30 | 300 | John | | Time | Cash | Employee | |----------------|----------| | 06:35 | 200 | McClane | | 06:37 | 200 | McClane | | 06:41 | 200 | McClane | </code></pre> <p>Thanks to all for replying, I'm trying with your answers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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