Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Combining data from two different queries
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
Karl Baum  
View profile  
 More options Oct 20, 11:21 am
From: Karl Baum <karl.b...@gmail.com>
Date: Tue, 20 Oct 2009 11:21:58 -0400
Local: Tues, Oct 20 2009 11:21 am
Subject: Combining data from two different queries

On our website we track visits and signups for each of our campaigns.  Visit
is a unique visit to the site and a visit is associated with a signup if
that user signs up.  I created a table for visits:

>> @table1 = Signup.report_table_by_sql "select count(*),c.code from signups

s,campaigns c where s.campaign_id=c.id and s.user_id is not null group by code"

+---------------------+
| code | signup_count |
+---------------------+
| abc  | 50           |
| dfg  | 50           |
+---------------------+

>> @table2 = Visit.report_table_by_sql "select count(*),c.code from visits

v,campaigns c where v.campaign_id=c.id group by code"

>> @table2.rename_column("count(*)", 'visit_count')

+--------------------+
| code | visit_count |
+--------------------+
| abc  | 300         |
| dfg  | 300         |
+--------------------+

What I would really like is to combine these two results into one table with
code, signup_count, visit_count, and conversion rate.

Thx.

-karl


    Reply    Reply to author    Forward  
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.
Andrew France  
View profile  
 More options Oct 20, 7:16 pm
From: Andrew France <andrew+li...@avito.co.uk>
Date: Wed, 21 Oct 2009 10:16:24 +1100
Local: Tues, Oct 20 2009 7:16 pm
Subject: Re: [ruport] Combining data from two different queries
Hi Karl,

Have you tried using SQL sub-selects? I can never remember the syntax
without looking it up but it's something like:
SELECT signup.code, signup.count, visit.count FROM (SELECT count(*),
c.code FROM signups s......) AS signup JOIN (SELECT ....) AS visit ON
visit.code = signup.code;

You can do this via either model, I don't think it cares what attributes
are returned!

Hope that helps!

Andrew


    Reply    Reply to author    Forward  
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.
Karl Baum  
View profile  
 More options Oct 20, 9:01 pm
From: Karl Baum <karl.b...@gmail.com>
Date: Tue, 20 Oct 2009 21:01:26 -0400
Local: Tues, Oct 20 2009 9:01 pm
Subject: Re: [ruport] Re: Combining data from two different queries
Hi Andrew.  I ended up using a slightly different approach.  Instead of
building the table directly from the SQL statement, I created a table
manually using methods on my ActiveRecord objects.  It ended up being much
simpler this way.  I think I was headed down the wrong path with my question
below.

Thanks for your help.

-karl

On 10/20/09 7:16 PM, "Andrew France" <andrew+li...@avito.co.uk> wrote:


    Reply    Reply to author    Forward  
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.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google