I have a MySQL query dated and when I execute it, it does not return any error or return any value to me

1

I have the following statement in mysql

select detalle_v.idp, producto.nombre, count(detalle_v.idp) as cantidad, detalle_v.precio as p_unitario, sum(detalle_v.precio) as total 
from detalle_v inner join producto on detalle_v.idp = producto.idp inner join t_precios on t_precios.idp = detalle_v.idp inner join venta on detalle_v.idv = venta.idv 
where date_format(venta.fecha, '%d-%m-%y') BETWEEN '24-07-2018' and '24-07-2018'
group by detalle_v.idp;

at the time of executing it, it does not mark any error but it does not return any value to me

    
asked by Hugo Costilla 25.07.2018 в 05:27
source

2 answers

1

Mainly in Mysql the format yyyy-MM-dd is used, I would recommend the following:

DATE(venta.fecha) BETWEEN DATE('2018-07-24') and DATE('2018-07-24')

understanding that sale.date is a type value DATETIME or DATE in the column

    
answered by 25.07.2018 в 05:39
0

I do not understand why you make a BETWEEN to NOT use a different date range, On the other hand, I would call the date in the corresponding format and then if you want to show it in a different way you change the format in the select, simply your query would leave it this way:

 select dv.idp, p.nombre, count(dv.idp) as cantidad, dv.precio as 
 p_unitario, sum(dv.precio) as total 
 from detalle_v dv 
 inner join producto p on dv.idp = p.idp 
 inner join t_precios tp on tp.idp = dv.idp 
 inner join venta v on dv.idv = v.idv 
 where v.fecha='2018-07-24'
 group by dv.idp;

Now if you get to use a BETWEEN I would do it knowing that I have a different range of dates:

 select dv.idp, p.nombre, count(dv.idp) as cantidad, dv.precio as 
 p_unitario, sum(dv.precio) as total 
 from detalle_v dv 
 inner join producto p on dv.idp = p.idp 
 inner join t_precios tp on tp.idp = dv.idp 
 inner join venta v on dv.idv = v.idv 
 where v.fecha between '2018-07-23' and '2018-07-24'
 group by dv.idp;
    
answered by 25.07.2018 в 16:05