-- Total Products by Category
-- Description
-- FILTER: {
--   filter: "class",
--   column: "products",
--   params: {
--     class: "text-right"
--   }
-- }

SELECT (SELECT ddc.name from simplebrsprod.deal_dealcategory ddc WHERE ddc.id = dc.first_global_brand_category_id) as category,
       to_char(count(DISTINCT dc.product_id), '999,999,999,999') as products,
       to_char(count(DISTINCT dc.prospect_product_id), '999,999,999,999') as prospects
FROM simplebrsprod.deal_cartitem dc
WHERE dc.cart_is_purchased = True AND dc.location_id = 5358688477118464
GROUP BY dc.first_global_brand_category_id
ORDER BY products desc;


