Untitled

mail@pastecode.io avatar
unknown
mysql
a year ago
957 B
10
Indexable
Never
SELECT 
    CONCAT('s', i.serialnumber) serial,
    p.siteflag,
    i.product,
    i.size,
    i.location,
    s.location AS prevloc,
    i.lastscandate,
    e.name
FROM
    (SELECT 
        serialnumber,
            Product,
            Size,
            Bin,
            Location,
            Previousbin AS PrevBin,
            PreviousLocation AS PrevLoc,
            Lastscandate,
            Username,
            SUBSTRING(username, 9, 10) - 1000 AS empid
    FROM
        shard.inventoryitemupdate
    WHERE
        username = 'agentId:4610'
            AND lastscandate >= '2023-04-10 08:21:00'
            AND lastscandate <= '2023-04-10 09:21:00'
            AND qtyonhand = 1
    ORDER BY lastscandate ASC) s
        JOIN 
    employee e ON e.id = s.empid
        JOIN
    inventoryitem i ON i.serialnumber = s.serialnumber
        JOIN
    product p ON p.code = i.product
WHERE
    i.location = 'returns'
        AND i.bin NOT LIKE 'b________%'