Topic: How to display matrix data?

Hi,

I need to produce a product matrix like this:

           group1            group2    
------------------------------------------------
group3     x                 y
group4   

x = SUM(products in group1 AND group3)
y = SUM(products in group2 AND group3)
etc


Here's my current model structure:
class Matrix < ActiveRecord::Base
  has_many :matrix_items
end

class MatrixItem < ActiveRecord::Base
  belongs_to :group
  # Each item here has a type to determine whether its an x-axis item or y-axis item
end

class Group < ActiveRecord::Base
  has_many :product_groups
  has_many :products, :through => :product_groups
end

class Product < ActiveRecord::Base
  has_many :product_groups
  has_many :groups, :through => :product_groups
end


I'm thinking of using a temporary table and find_by_sql just thought I'd check if anyone has any better suggestions?

Cheers
Luke