Advertisement
eugenpotlog

ecomitems_flip

Aug 8th, 2024
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.78 KB | None | 0 0
  1. SELECT
  2.     event_date,
  3.     item_id,
  4.     item_name,
  5.     item_brand,
  6.     item_category,
  7.     item_battery,
  8.     item_capacity,
  9.     item_colour,
  10.     item_condition,
  11.     item_stock,
  12.     SUM(CASE WHEN event_name = 'view_item' THEN 1 ELSE 0 END) AS total_items_viewed,
  13.     SUM(CASE WHEN event_name = 'add_to_cart' THEN 1 ELSE 0 END) AS total_adds_to_cart,
  14.     SUM(CASE WHEN event_name = 'add_to_cart' THEN quantity ELSE 0 END) AS total_adds_to_cart_qty,
  15.     SUM(CASE WHEN event_name = 'add_to_wishlist' THEN 1 ELSE 0 END) AS total_adds_to_wishlist,
  16.     SUM(CASE WHEN event_name = 'view_cart' THEN 1 ELSE 0 END) AS total_carts_viewed,
  17.     SUM(CASE WHEN event_name = 'remove_from_cart' THEN 1 ELSE 0 END) AS total_removes_from_cart,
  18.     SUM(CASE WHEN event_name = 'remove_from_cart' THEN quantity ELSE 0 END) AS total_removes_from_cart_qty,    
  19.     SUM(CASE WHEN event_name = 'begin_checkout' THEN 1 ELSE 0 END) AS total_checkouts_started,
  20.     SUM(CASE WHEN event_name = 'begin_checkout' THEN quantity ELSE 0 END) AS total_checkouts_started_qty,        
  21.     SUM(CASE WHEN event_name = 'purchase' THEN 1 ELSE 0 END) AS total_purchases,
  22.     SUM(CASE WHEN event_name = 'purchase' THEN quantity ELSE 0 END) AS total_purchase_qty,
  23.     SUM(CASE WHEN event_name = 'purchase' THEN item_revenue ELSE 0 END) AS total_purchase_revenue,    
  24.     SUM(CASE WHEN event_name = 'refund' THEN 1 ELSE 0 END) AS total_refunds
  25. FROM
  26.     `cogent-node-249607.dataform_output.ro_output_ga4_ecom`
  27. WHERE
  28.   event_name IN ('view_item', 'add_to_cart', 'add_to_wishlist', 'view_cart', 'remove_from_cart', 'begin_checkout', 'purchase', 'refund')
  29. GROUP BY
  30.     event_date,
  31.     item_id,
  32.     item_name,
  33.     item_brand,
  34.     item_category,
  35.     item_battery,
  36.     item_capacity,
  37.     item_colour,
  38.     item_condition,
  39.     item_stock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement