a complicated calculation query.. for me

Discussion in 'MySQL' started by levivel, May 6, 2010.

  1. #1
    There is a database with the following structure:

    var1: unique identifier
    var2: eventtime
    var3: activity

    Each unique identifier can have multiple eventtimes because the unique identifier refers to individual bees in an experiment. Some unique identifiers have 3 eventtimes, others have 400.

    The goal is to create a calculated field where each subsequent eventtime for a given unique identifier is compared to the first one. Let me show an example of what I mean:

    16356 ....... 0
    16356 ....... 5
    16356 ....... 7
    52656 ....... 0
    52656 ....... 1
    ... etc

    How would I create this calculated field?
    Below is my (bad) attempt at getting this solution:

    select uid, YEAR(eventtime), MONTH(eventtime), DAY(eventtime), HOUR(eventtime), MINUTE(eventtime), uid||eventtime in (select uid||time_to_sec(timediff(eventtime,min(eventtime))) as elapsed from alldata), activity
           from alldata
           where activity in ('concentric','radial')
           group by uid, YEAR(eventtime), MONTH(eventtime), DAY(eventtime), HOUR(eventtime), MINUTE(eventtime)
           order by uid, eventtime
    Code (markup):
    Thanks!
     
    levivel, May 6, 2010 IP