[vox-tech] MySQL question: making stats out of orders

Bill Kendrick nbs at sonic.net
Tue Dec 1 22:33:25 PST 2009


On Wed, Dec 02, 2009 at 12:20:25AM -0600, Chanoch (Ken) Bloom wrote:
> INSERT into orderstats(productid, date, orders)
> SELECT
>      orderitem.productid, orders.timestamp, SUM(orderitem.qty)
> FROM orderitem
>   JOIN orders ON orders.id = orderitem.orderid
>   WHERE orders.timestamp >= { 90 days ago }
> group by orderitem.productid, orders.timestamp
> 
> assuming orders.timestamp has one-day granularity

Timestamp is actually a timestamp (down the second).

-bill!


More information about the vox-tech mailing list