app/controllers/analytics_controller.rb
# Grabs the id and name of the top products
Grabs the id and name of the top products
Grabs the id and name of the top products
def top_prod_query(cat)
    con = ActiveRecord::Base.connection
    if cat == -1
      cat = ""
    else
      cat = "WHERE prod.category_id = #{cat.to_s}"
    end
    sql = "
      SELECT topkek.id, topkek.unique_name
      FROM
      (
        SELECT prod.id, prod.unique_name, COALESCE(prod.price * pur.totalQuantity, 0) AS total
        FROM Products prod
        LEFT OUTER JOIN
        (
          SELECT purch.product, SUM(purch.quantity) AS totalQuantity
          FROM Purchases purch
          GROUP BY purch.product
          ORDER BY totalQuantity
        ) AS pur
        ON prod.id = pur.product
        #{cat}
        ORDER BY total DESC
        LIMIT 50
      ) AS topkek
      ORDER BY topkek.unique_name;
      "
  return con.execute(sql)
  rescue
      return []
  end
def top_prod_query ( cat ) con = ActiveRecord :: Base . connection if cat == - 1 cat = "" else cat = "WHERE prod.category_id = #{cat.to_s}" end sql = "
      SELECT topkek.id, topkek.unique_name
      FROM
      (
        SELECT prod.id, prod.unique_name, COALESCE(prod.price * pur.totalQuantity, 0) AS total
        FROM Products prod
        LEFT OUTER JOIN
        (
          SELECT purch.product, SUM(purch.quantity) AS totalQuantity
          FROM Purchases purch
          GROUP BY purch.product
          ORDER BY totalQuantity
        ) AS pur
        ON prod.id = pur.product
        #{cat}
        ORDER BY total DESC
        LIMIT 50
      ) AS topkek
      ORDER BY topkek.unique_name;
      " return con . execute ( sql ) rescue return [ ] end
Grabs the id and name of the top products
Grabs the id and name of the top products
cat
<not_specific>