# Ruby on Rails and Star Schemas Question

**URL:** <https://www.ruby-forum.com/t/ruby-on-rails-and-star-schemas-question/64708>\
**Category:** Ruby\
**Created:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-and-star-schemas-question/64708 "2006-08-15T14:18:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Garcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bb73d2/32.png) [@Anthony\_Garcia](https://www.ruby-forum.com/u/Anthony_Garcia)\
**Post date:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-and-star-schemas-question/64708/1 "2006-08-15T14:18:00Z")

</div>

Good morning,

I’m a ruby on rails newby and trying to figure out how I can execute a  
star  
schema query like this.

select generators.Unit,  
thedates.weekday\_name,  
hours.thehour,  
sum(generatorfacts.revenue)  
from  
generatorfacts,  
generators,  
thedates,  
hours  
where  
generatorfacts.hour\_id = hours.id and  
generatorfacts.thedate\_id = thedates.id and  
generatorfacts.generator\_id = generators.id and  
thedates.weekday\_name = ‘Monday’  
group by generators.Unit,thedates.weekday\_name,hours.thehour  
having sum(generatorfacts.rtrevenue) \> 0

This is a standard data warehouse type, star schema query.

I’ve been reading and trying things in script console but I’m hoping  
someone  
out there can give me a head start.  
I’m as far using has\_many :through, and belongs\_to in my models. I’ve  
also  
heard that someone named Ken Kunz is developing an acts\_as\_fact plugin  
which  
may be just what I need. Can anybody walk me through how I would  
approach  
this?

Regards,  
Anthony

---

<div class="post-metadata">

**Author:** ![Anthony\_Garcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bb73d2/32.png) [@Anthony\_Garcia](https://www.ruby-forum.com/u/Anthony_Garcia)\
**Post date:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-and-star-schemas-question/64708/2 "2006-08-15T14:18:02Z")

</div>

On Aug 12, 2006, at 10:55 AM, Anthony Garcia wrote:

> from  
> having sum(generatorfacts.rtrevenue) \> 0  
> may be just what I need. Can anybody walk me through how I would  
> approach  
> this?

Well first, you want the ruby on rails mailing list. Secondly, you  
may just want to use ActiveRecord::Base#find\_by\_sql for this, since  
you already seem to know exactly what you want.
