Skip to content

Instantly share code, notes, and snippets.

@drewgillson
Created June 2, 2012 13:52

Revisions

  1. drewgillson revised this gist Jun 2, 2012. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion CustomerWishlist.sql
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,9 @@
    SELECT b.email, c.value AS name, a.updated_at, d.added_at, d.product_id, e.name, SUM(g.qty_ordered) AS purchased FROM `wishlist` AS a INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id AND c.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'firstname' AND entity_type_id = b.entity_type_id) INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id INNER JOIN catalog_product_flat_1 AS e ON d.product_id = e.entity_id LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email LEFT JOIN sales_flat_order_item AS g ON (f.entity_id = g.order_id AND g.sku LIKE CONCAT(e.sku,'%') AND g.product_type = 'simple')
    SELECT b.email, c.value AS name, a.updated_at, d.added_at, d.product_id, e.name, SUM(g.qty_ordered) AS purchased
    FROM `wishlist` AS a
    INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id
    INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id AND c.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'firstname' AND entity_type_id = b.entity_type_id)
    INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id
    INNER JOIN catalog_product_flat_1 AS e ON d.product_id = e.entity_id
    LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email
    LEFT JOIN sales_flat_order_item AS g ON (f.entity_id = g.order_id AND g.sku LIKE CONCAT(e.sku,'%') AND g.product_type = 'simple')
    GROUP BY b.email, c.value, a.updated_at, d.added_at, d.product_id, e.name
  2. drewgillson created this gist Jun 2, 2012.
    2 changes: 2 additions & 0 deletions CustomerWishlist.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    SELECT b.email, c.value AS name, a.updated_at, d.added_at, d.product_id, e.name, SUM(g.qty_ordered) AS purchased FROM `wishlist` AS a INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id AND c.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'firstname' AND entity_type_id = b.entity_type_id) INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id INNER JOIN catalog_product_flat_1 AS e ON d.product_id = e.entity_id LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email LEFT JOIN sales_flat_order_item AS g ON (f.entity_id = g.order_id AND g.sku LIKE CONCAT(e.sku,'%') AND g.product_type = 'simple')
    GROUP BY b.email, c.value, a.updated_at, d.added_at, d.product_id, e.name