select date(v1.sold_ts) as dd,sum(v2.price),count(*),
sum(if(v2.price is null,1,0)) as prices_missing
from vending_log v1 left join vending_price v2 on
(v1.product_id = v2.product_id and
date(v1.sold_ts) between v2.valid_from and v2.valid_to)
group by dd;