-- Number of items per Order Guide
-- This report the count of items in Order Guides
-- FILTER: {
--   filter: "link",
--   column: "link"
-- }
-- FILTER: {
--   filter: "date",
--   column: "create_date",
--   params: {
--     "format": "m/d/y"
--   }
-- }

SELECT dc.name,
       dc.id,
       count(dc.id) as items,
       (select bl.name from simplebrsprod.business_location bl where bl.id = dc.location_id) as business_name,
       concat('https://simple123.com/business/locations/', dc.location_id, '/orderguides/', dc.id) as link
from simplebrsprod.deal_cart dc, simplebrsprod.deal_cartitem dci
Where dc.id = dci.cart_id and dc."polyclassC" = 'BidCart'
GROUP BY dc.name,
         dc.id,
         dc.location_id
ORDER BY items desc;