Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2009, 17:15
Avatar de lair
lair
 
Fecha de Ingreso: enero-2009
Ubicación: header('Location: Morelia");
Mensajes: 1.052
Antigüedad: 15 años, 4 meses
Puntos: 46
Consulta between con fechas

Hola a todos.

tengo un problema con la siguiente consulta,

tengo esta que me extrae una fecha de acuerdo a el mes y el dia
Código:
mysql> select distinct date
 from reporte
 where month(date)='08' and day(date)='15' order by date asc limit 1;
+---------------------+
| date                |
+---------------------+
| 2009-08-15 00:29:33 | 
+---------------------+
1 row in set (0.00 sec)
y otra que es igual pero extraigo el mes anterior
Código:
mysql> select distinct date
 from reporte
 where month(date)=08-1 and day(date)='15' order by date asc limit 1;
+---------------------+
| date                |
+---------------------+
| 2009-07-15 08:23:42 | 
+---------------------+
1 row in set (0.00 sec)
y cuando intento combinarlas de la siguiente manera el resultado es algo inesperado
Código:
mysql> select *
 from reporte
 where date between
(select distinct date from reporte where month(date)=08-1 and day(date)=15 order by date asc limit 1)
 and
 (select distinct date from reporte where month(date)=08 and day(date)=15 order by date asc limit 1) limit 100;
cuando las combino asi solo me extrae los registros que son dia 15 del mes anterior en este caso 07 "julio" (08-1)

de antemano muchas gracias.


Ya quedo tenia un limit de mas

select *
from reporte
where date between
(select distinct date from reporte where month(date)=08-1 and day(date)=15 order by date asc limit 1)
and
(select distinct date from reporte where month(date)=08 and day(date)=15 order by date asc limit 1) limit 100;

Última edición por lair; 20/08/2009 a las 17:21 Razón: Solucionado