MySQL Forums
Forum List  »  Spanish

Re: Consulta MySQL
Posted by: Marco Rios
Date: February 06, 2018 11:48PM

Carolina,
En MySQL las fechas se almacenan en el formato siguiente:
'yyyy-mm-dd' en el caso de columnas del tipo DATE
y
'yyyy-mm-dd hh:mm:ss' en columnas del tipo DATE TIME

Ejemplo:
'2017-12-31 14:26:54'

por lo que tu condición
 WHERE FA.FECHA_ATENCION BETWEEN '01/01/17' AND '31/12/2017'

Carece de sentido, tal vez la podrías cambiar por
 WHERE FA.FECHA_ATENCION BETWEEN '2017-01-01' AND '2017-12-31'

Adicionalmente, para obtener las atenciones MENSUALES, deberías agrupar los datos de forma similar a la siguiente:
GROUP BY ES.NOMBRE, YEAR(FA.FECHA_ATENCION), MONTH(FA.FECHA_ATENCION)

y tu consulta quedaría así:
SELECT ES.NOMBRE, YEAR(FA.FECHA_ATENCION) AS AÑO, MONTH(FA.FECHA_ATENCION) AS MES, COUNT(*) AS CANTIDAD
FROM 
     ATENCION_HISTORICO FA 
           JOIN 
     ESPECIALIDAD_MEDICO ESM ON FA.ESP_ID = ESM.ESP_ID
          JOIN 
     ESPECIALIDAD ES ON ESM.ESP_ID = ES.ESP_ID 
WHERE 
       FA.FECHA_ATENCION BETWEEN '2017-01-01' AND '2017-12-31'
GROUP BY 
       ES.NOMBRE, YEAR(FA.FECHA_ATENCION), MONTH(FA.FECHA_ATENCION)
ORDER BY 
       ES.NOMBRE, FA.FECHA_ATENCION;

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
880
November 17, 2017 06:04PM
Re: Consulta MySQL
433
February 06, 2018 11:48PM


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.