select to_Days(date_purchased) as aday,
round(date_purchased/1000000)  as SalesDate,  
sum(value) as SalesValue
from <@PREFIX>jshopping_orders,<@PREFIX>jshopping_orders_total
where <@PREFIX>jshopping_orders.orders_id = <@PREFIX>jshopping_orders_total.orders_id 
and orders_total.class ="ot_total"
and date_purchased <= %s
and date_purchased >= %s
group by to_Days(date_purchased)
order by date_purchased desc