Rails - How to create advanced arrays that sums columns?
How do I create an array that sums the column earn on a date.
So it would output like:
[<sum of 'earn' where dato=2011-02-14>, <sum of 'earn' where dato=2011-02-15>]
And how to create a pointstart, that finds the last date.
My table
id virksomhed dato earn
9 Euroads 2011-02-15 00:00:00 4
10 Euroads 2011-02-15 00:00:00 4
11 Iqmedier 2011-02-15 00:00:00 2
12 Iqmedier 2011-02-15 00:00:00 3
12 Iqmedier 2011-02-14 00:00:00 3
{
name: "Indtjening",
pointInterval: <%= 1.day * 1000 %>,
pointStart: How to create point start,
data:
},
{
name: "Iqmedier",
color: '#DBD200',
pointInterval: <%= 1.day * 1000 %>开发者_如何学JAVA,
pointStart: How to create point start,
data: <%= Reklamer.where(:virksomhed => 'Iqmedier').all.map(&:earn) %>
}
,
{
name: "Euroads",
color: '#1B7B94',
pointInterval: <%= 1.day.to_i * 1000 %>,
pointStart: How to create point start,
data: <%= Reklamer.where(:virksomhed => 'Euroads').all.map(&:earn) %>
}
Reklamer.sum(:earn, :group => :dato)
#<OrderedHash { 2011-02-14 00:00:00 => 3, 2011-02-15 00:00:00 => 13}>
Model.find(:all, :select => 'sum(earn) AS earn', :group => 'dato').map(&:earn)
精彩评论