Mysql
 sql >> Database >  >> RDS >> Mysql

Recupero delle righe il cui valore si trova tra due righe con una determinata condizione

Prova questa query

SELECT *
FROM products
WHERE items = 'apple'
AND itemtype = '1'
AND id > 
    (
        SELECT MIN(id) AS id
        FROM products
        WHERE items = 'apple'
        AND itemtype = '1'
    )
AND id < 
    (
        SELECT MIN(id)
        FROM products
        WHERE items = 'apple'
        AND itemtype = '0'
        AND id > 
            (
                SELECT MIN(id) AS id
                FROM products
                WHERE items = 'apple'
                AND itemtype = '1'
            )
    );