Skip to main content
update
Origen Enlace
user46896
user46896
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND ((PVD_Year='2020' AND PVD_Month ='12') OR (PVD_Year='2021' AND PVD_Month ='01') OR (PVD_Year='2021' AND PVD_Month ='02'))ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND ((PVD_Year='2020' AND PVD_Month ='12') OR (PVD_Year='2021' AND PVD_Month ='01') OR (PVD_Year='2021' AND PVD_Month ='02'))ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND CONCAT(PVD_Year, '-',PVD_Month) IN ('2021-02', '2021-01', '2020-12') ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND CONCAT(PVD_Year, '-',PVD_Month) IN ('2021-02', '2021-01', '2020-12') ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT
    MAX(KeyIdT_VEN_PVD),
    PVD_Prod_Code,
    CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
    PVD_PVDU,
    PVD_PVDP
FROM
    VEN_TempPVD
WHERE
    PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
GROUP BY
    KeyIdT_VEN_PVD
ORDER BY
    PVD_Prod_Code ASC,
    PVD_Year ASC,
    PVD_Month ASC;
    SELECT
        MAX(KeyIdT_VEN_PVD),
        PVD_Prod_Code,
        CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
        PVD_PVDU,
        PVD_PVDP
    FROM
        VEN_TempPVD
    WHERE
        PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
    GROUP BY
        KeyIdT_VEN_PVD
    ORDER BY
        PVD_Prod_Code ASC,
        PVD_Year ASC,
        PVD_Month ASC;
SELECT
    MAX(KeyIdT_VEN_PVD),
    PVD_Prod_Code,
    CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
    PVD_PVDU,
    PVD_PVDP
FROM
    VEN_TempPVD
WHERE
    PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
GROUP BY
    KeyIdT_VEN_PVD
ORDER BY
    PVD_Prod_Code ASC,
    PVD_Year ASC,
    PVD_Month ASC;
    SELECT
        MAX(KeyIdT_VEN_PVD),
        PVD_Prod_Code,
        CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
        PVD_PVDU,
        PVD_PVDP
    FROM
        VEN_TempPVD
    WHERE
        PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
    GROUP BY
        KeyIdT_VEN_PVD
    ORDER BY
        PVD_Prod_Code ASC,
        PVD_Year ASC,
        PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND ((PVD_Year='2020' AND PVD_Month ='12') OR (PVD_Year='2021' AND PVD_Month ='01') OR (PVD_Year='2021' AND PVD_Month ='02'))ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND CONCAT(PVD_Year, '-',PVD_Month) IN ('2021-02', '2021-01', '2020-12') ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT
    MAX(KeyIdT_VEN_PVD),
    PVD_Prod_Code,
    CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
    PVD_PVDU,
    PVD_PVDP
FROM
    VEN_TempPVD
WHERE
    PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
GROUP BY
    KeyIdT_VEN_PVD
ORDER BY
    PVD_Prod_Code ASC,
    PVD_Year ASC,
    PVD_Month ASC;
SELECT
    MAX(KeyIdT_VEN_PVD),
    PVD_Prod_Code,
    CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
    PVD_PVDU,
    PVD_PVDP
FROM
    VEN_TempPVD
WHERE
    PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
GROUP BY
    KeyIdT_VEN_PVD
ORDER BY
    PVD_Prod_Code ASC,
    PVD_Year ASC,
    PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND ((PVD_Year='2020' AND PVD_Month ='12') OR (PVD_Year='2021' AND PVD_Month ='01') OR (PVD_Year='2021' AND PVD_Month ='02'))ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
SELECT PVD_Prod_Code, PVD_Year, PVD_Month, PVD_PVDU, PVD_PVDP FROM VEN_TempPVD WHERE PVD_Prod_Code IN ('00277','00285') AND CONCAT(PVD_Year, '-',PVD_Month) IN ('2021-02', '2021-01', '2020-12') ORDER BY PVD_Prod_Code ASC, PVD_Year ASC, PVD_Month ASC;
    SELECT
        MAX(KeyIdT_VEN_PVD),
        PVD_Prod_Code,
        CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
        PVD_PVDU,
        PVD_PVDP
    FROM
        VEN_TempPVD
    WHERE
        PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
    GROUP BY
        KeyIdT_VEN_PVD
    ORDER BY
        PVD_Prod_Code ASC,
        PVD_Year ASC,
        PVD_Month ASC;
    SELECT
        MAX(KeyIdT_VEN_PVD),
        PVD_Prod_Code,
        CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
        PVD_PVDU,
        PVD_PVDP
    FROM
        VEN_TempPVD
    WHERE
        PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
    GROUP BY
        KeyIdT_VEN_PVD
    ORDER BY
        PVD_Prod_Code ASC,
        PVD_Year ASC,
        PVD_Month ASC;
se añadieron 136 caracteres en el cuerpo
Origen Enlace
user46896
user46896

¿Cómo puedo obtener el ultimo registro de cada periodo?

he creado un ejemplo mínimo aquí:   

http://sqlfiddle.com/#!9/ac62c97/1/0

Update

intente implementar inner join pero solo obtengo los datos de un producto:

http://sqlfiddle.com/#!9/3ada23/3/0

SELECT
    MAX(KeyIdT_VEN_PVD),
    PVD_Prod_Code,
    CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
    PVD_PVDU,
    PVD_PVDP
FROM
    VEN_TempPVD
WHERE
    PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
GROUP BY
    KeyIdT_VEN_PVD
ORDER BY
    PVD_Prod_Code ASC,
    PVD_Year ASC,
    PVD_Month ASC;

¿Cómo puedo obtener el ultimo registro de cada periodo?

¿Cómo puedo obtener el ultimo registro de cada periodo?

he creado un ejemplo mínimo aquí:  http://sqlfiddle.com/#!9/ac62c97/1/0

he creado un ejemplo mínimo aquí: 

http://sqlfiddle.com/#!9/ac62c97/1/0

Update

intente implementar inner join pero solo obtengo los datos de un producto:

http://sqlfiddle.com/#!9/3ada23/3/0

SELECT
    MAX(KeyIdT_VEN_PVD),
    PVD_Prod_Code,
    CONCAT(PVD_Year, '-', PVD_Month) AS PVD_Period,
    PVD_PVDU,
    PVD_PVDP
FROM
    VEN_TempPVD
WHERE
    PVD_Prod_Code IN('00277') AND CONCAT(PVD_Year, '-', PVD_Month) IN('2021-09', '2021-08', '2021-07')
GROUP BY
    KeyIdT_VEN_PVD
ORDER BY
    PVD_Prod_Code ASC,
    PVD_Year ASC,
    PVD_Month ASC;

¿Cómo puedo obtener el ultimo registro de cada periodo?

etiquetas editadas
Enlace
user46896
user46896
Origen Enlace
user46896
user46896
Loading