Untitled

mail@pastecode.io avatar
unknown
mysql
7 days ago
1.9 kB
5
Indexable
Never
SELECT 
    c.label, d.*
FROM
    (SELECT 
    MAX(reasoncode) reasoncode,
    MAX(createdate) removedate,
    CONCAT('s', t2.serialnumber) serial,
    product,
    size,
    location,
    previouslocation,
    SUBSTRING_INDEX(MIN(source), 'Manual Adjust by ', - 1) source,
    SUBSTRING_INDEX(notes, ']', 1) notes
FROM
    (SELECT 
        id AS decrementid, reasoncode, source
    FROM
        inventoryupdate
    WHERE
        updateday >= CURRENT_DATE) t1
        JOIN
    inventoryupdate_extend t2 ON inventoryupdateid = decrementid
        JOIN
    inventoryitem t3 ON t2.serialnumber = t3.serialnumber
WHERE
    createdate >= CURRENT_DATE
        AND notes LIKE '[Manual decrement%'
        AND removedate >= CURRENT_DATE
GROUP BY serial) d
        JOIN
    (SELECT 
        code, label
    FROM
        inventoryupdatereasoncode
    GROUP BY code) c ON d.reasoncode = c.code
GROUP BY serial
ORDER BY removedate DESC;

SELECT 
    c.label, d.*
FROM
    (SELECT 
        MAX(reasoncode) reasoncode,
            MAX(createdate) AS incrementdate,
            CONCAT('s', t2.serialnumber) serial,
            product,
            size,
            location,
            previouslocation,
            SUBSTRING_INDEX(MIN(source), 'Manual Adjust by ', - 1) source,
            SUBSTRING_INDEX(notes, ']', 1) notes
    FROM
        (SELECT 
        id AS decrementid, reasoncode, source
    FROM
        inventoryupdate
    WHERE
        updateday >= CURRENT_DATE) t1
    JOIN inventoryupdate_extend t2 ON inventoryupdateid = decrementid
    JOIN inventoryitem t3 ON t2.serialnumber = t3.serialnumber
    WHERE
        createdate >= CURRENT_DATE
            AND notes LIKE '[Manual Increment%'
            AND createdate >= CURRENT_DATE
    GROUP BY serial) d
        JOIN
    (SELECT 
        code, label
    FROM
        inventoryupdatereasoncode
    GROUP BY code) c ON d.reasoncode = c.code
GROUP BY serial
ORDER BY incrementdate DESC;
Leave a Comment