MySQL Forums
Forum List  »  Spanish

Re: [QUERY] obtener valores "no agregados" en GROUP BY
Posted by: Marco Rios
Date: February 04, 2017 10:12PM

Alguien me comentó que debía usar un SELF JOIN, y después de varias horas de reflexión, aquí está la
SOLUCIÓN:
SELECT 
    t.id_contrato, t.id_tarifa, t.fecha, t.tarifa
FROM
    tarifas t
        JOIN
    (SELECT 
        fecha, MIN(tarifa) AS tar_min
    FROM
        tarifas
    GROUP BY fecha) tmin
WHERE
    t.fecha BETWEEN '2017-04-15' AND '2017-04-19'
        AND t.fecha = tmin.fecha
        AND t.tarifa = tmin.tar_min
ORDER BY t.fecha , t.id_contrato

Espero que a alguien le sirva.

y con esto se comprueba lo siguiente:
LLEGAR AL PLANTEAMIENTO CORRECTO DE UN PROBLEMA, NOS LLEVA CASI A LA SOLUCIÓN DEL MISMO.

Thanks in advance for your valuable help.

Acer Aspire 2920
CPU: Intel Core 2 Duo T7300@2.00GHzX2
RAM: 4GB
Graphics: Intel 965GM
OS: UBUNTU 16.04 LTS 64bits
--
Best regards
Marco
Mexico City, Mexico

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: [QUERY] obtener valores "no agregados" en GROUP BY
133
February 04, 2017 10:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.