D
D
disable19922014-06-13 12:11:56
MySQL
disable1992, 2014-06-13 12:11:56

Offset filtering?

I have the following dataset

s1  in1  out1  t1  date1
s2  in2  out2  t2  date2
...
si  ini  outi  ti  datei

where date is the date the session started (DATETIME) and time is how long the session lasted in seconds (BIGINT).
You need a query with the following filtering:
строка попадает в результат запроса если:
    datei+1-datei<ti

The fact is that there are effective records in the database, and so they can be filtered out. Bicycle programmatically write not hunting. Can this be done in a MySQL query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
disable1992, 2014-06-13
@disable1992

SELECT
    *
FROM
    (
        SELECT
        Table1.s1,
        Table1.date,
        Table1.t,
        (
        SELECT
           MIN(tbl.s1) AS s1
        FROM
           Table1 AS tbl
        WHERE 
            tbl.s1 > Table1.s1
        ) as NextId
    FROM
        Table1
) AS tblInner
JOIN Table1 AS Next
    ON tblInner.NextId=Next.s1
WHERE TIMESTAMPDIFF(SECOND,Next.date,tblInner.date)<tblInner.t

Prompted on the "stack". Now we adapt to a real database)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question