app/controllers/admin/store/reports_controller.rb
def purchase_frequency
    sql = <<-EOF
      select order_count, count(*) as num_users
      from (select shipping_name, COUNT(*) as order_count 
      	  from store_orders 
          where status in ('submitted', 'completed', 'shipped', 'unshipped')
          and submitted > '#{@start_date}' and submitted < '#{@end_date}'
          and sales_channel LIKE '#{@selected_channel}'
      	  group by user_id) as dt
      group by order_count
      order by order_count desc;
    EOF

    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
  end
# A report showing hot many times a product was purchased
A report showing hot many times a product was purchased
A report showing hot many times a product was purchased
def purchase_frequency
    sql = <<-EOF
      select order_count, count(*) as num_users
      from (select shipping_name, COUNT(*) as order_count 
      	  from store_orders 
          where status in ('submitted', 'completed', 'shipped', 'unshipped')
          and submitted > '#{@start_date}' and submitted < '#{@end_date}'
          and sales_channel LIKE '#{@selected_channel}'
      	  group by user_id) as dt
      group by order_count
      order by order_count desc;
    EOF
    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
  end
def purchase_frequency sql = <<-EOF 
      select order_count, count(*) as num_users
      from (select shipping_name, COUNT(*) as order_count 
      	  from store_orders 
          where status in ('submitted', 'completed', 'shipped', 'unshipped')
          and submitted > ' #{ @start_date } ' and submitted < ' #{ @end_date } '
          and sales_channel LIKE ' #{ @selected_channel } '
      	  group by user_id) as dt
      group by order_count
      order by order_count desc;
     EOF @data = [ ] ActiveRecord :: Base . connection . execute ( sql ) . each { | row | @data << row } end
A report showing hot many times a product was purchased
A report showing hot many times a product was purchased