app/controllers/admin/store/reports_controller.rb
def user_leaderboard
    sql = <<-EOF
      select shipping_name, user_id, count(id), sum(total)
      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
      order by count(id) desc;
    EOF

    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
  end
# Report of users who have placed the most orders
Report of users who have placed the most orders
Report of users who have placed the most orders
def user_leaderboard
    sql = <<-EOF
      select shipping_name, user_id, count(id), sum(total)
      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
      order by count(id) desc;
    EOF
    @data = []
    ActiveRecord::Base.connection.execute(sql).each { |row| @data << row }
  end
def user_leaderboard sql = <<-EOF 
      select shipping_name, user_id, count(id), sum(total)
      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
      order by count(id) desc;
     EOF @data = [ ] ActiveRecord :: Base . connection . execute ( sql ) . each { | row | @data << row } end
Report of users who have placed the most orders
Report of users who have placed the most orders