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 LENOVO G450
CPU: Pentium(R) Dual-Core CPU T4400 @ 2.20GHz × 2
RAM: 4GB
Graphics: Intel GM45
OS: UBUNTU 18.04.4 LTS 64bits
GNOME 3.28.2
--
Best regards
Marco
Mexico City, Mexico

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: [QUERY] obtener valores "no agregados" en GROUP BY
436
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.