Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Posts
    3

    Unanswered: select statement

    hi everyone!

    i have a table named answer, it has columns: id, name, date, time, and flag. flag could
    only be 0 and 1. the table tells the answer of <name> if it's correct (1) or not(0). i want to select only the <name>s with five consecutive flags equal to 1. a consecutive answer of a <name> can be determine through the date and time columns, but i don't know how to create the select statement. help, anyone?

    thanks.

  2. #2
    Join Date
    Mar 2004
    Posts
    110
    SELECT * FROM anwser where flag=1 LIMIT 5

    resultset will only display 5 rows where flag=1

    -Ed

  3. #3
    Join Date
    May 2004
    Posts
    3
    ed, thanks for replying...

    but the result that the select statement you gave is not the one i need because it can also return a non-consecutive flag=1.
    i.e:
    id name date time flag
    1 name1 2004-05-03 12:02:00 1
    2 name1 2004-05-03 12:03:00 0
    3 name1 2004-05-03 12:04:03 1
    4 name1 2004-05-03 12:05:03 1
    5 name1 2004-05-03 12:06:03 1
    6 name1 2004-05-03 12:04:03 1
    7 name1 2004-05-03 12:04:03 1

    in the statement: select * from answer where flag=1 limit 5, it will return rows with id: 1,3,4,5,6 but i need a statement that would return only rows with id: 3,4,5,6,7 because those are the 5 consecutive rows with flags=1

    thanks...

  4. #4
    Join Date
    Mar 2004
    Posts
    110
    ah, i see what you mean now.

    But their is a little problem.

    No way in hell you will be able to get a select statement to do what you want. (atleast, not to my knowledge)

    Perhaps in a funtion.. but even then, it will be a tough one (i wouldnt know how to attack it)

    Perhaps if you explain more about your intentions, the anwser can be found in a diffrent way.

    -Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •