CartMetrix - Do you know yours?

« ZenCart Inventory Report | Home | MySQL Slow Query Logging »

11/29/2006

ZenCart Orders Total Weight Query

SELECT op.products_quantity * SUM( products_weight )
FROM products p
JOIN orders_products op
WHERE p.products_id
IN (
SELECT products_id
FROM orders_products
WHERE orders_id = 'ORDER_ID'
)
AND op.orders_id = 'ORDER_ID'

Replace ORDER_ID with the orders_id in question.

Requires MySQL 4.1 or better for subselect support

Related Link: Bowflex

Popularity: 13%

Trackback:

Related Posts

2 Responses to “ZenCart Orders Total Weight Query”

  1. mo said:

    your query does not count more than 1 items of the same products
    more accurate query should be sth like this:

    SELECT op.products_quantity*sum(p.products_weight)
    FROM products p JOIN orders_products op
    WHERE p.products_id IN (SELECT products_id FROM orders_products WHERE orders_id = ‘ORDER_ID’)
    AND op.orders_id = ‘ORDER_ID’

  2. damonp said:

    Good catch!

    I updated the original query to avoid confusion.

Post your opinion

Verification Image

Please type the letters you see in the picture.

Subscribe without commenting


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2009 damonparker.org. all rights reserved.

Close
E-mail It