Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion help with aggregation & group by
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chuck Remes  
View profile  
 More options Nov 5 2007, 10:43 pm
From: Chuck Remes <cremes.devl...@mac.com>
Date: Mon, 5 Nov 2007 21:43:23 -0600
Local: Mon, Nov 5 2007 10:43 pm
Subject: help with aggregation & group by
I have a table where I'm trying to get the average time delta for each  
minute of the past X minutes. I have the SQL written and working but  
I'm unsure how to translate it into Sequel ruby; it may not even be  
possible but I thought I'd ask the list.

Here's my table definition and the SQL I am running against it:

class Order < Sequel::Model(:orders)
set_schema do
   primary_key :id, :auto_increment => true
   varchar :market, :size => 12
   decimal :created_at, :elements => [15,5]
   decimal :ack, :elements => [15,5]
end
end

select market, minute(from_unixtime(ack)) AS minute, round(avg((ack -  
created_at) * 1000), 2) AS ack_average from orders  where 'ack' >  
(UNIX_TIMESTAMP(now()) - (15 * 60) and 'market' = 'ICE' group by  
minute(from_unixtime(ack));

As you may infer, the ack and created_at columns are large floating  
point numbers (seconds plus microseconds) representing time relative  
to the UNIX epoch. Is it possible to write this in Sequel and have it  
generate the correct SQL? Here's an attempt...

market = 'ICE'
Order.filter{:market => market && :ack >  
15.minutes.ago}.avg(:no_idea_what_to_do_from_here).group(:still_lost)

I need to do math (subtraction) on two columns in the result set and  
average that value. I also need access to mysql's +minute+ function  
and +unix_timestamp+ function. I looked through the code but got lost  
pretty quickly when trying to figure out how to monkey patch this in.

Am I best off just executing the SQL above and saving it into a  
dataset for ruby manipulation?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.