Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6363521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:02:56+00:00 2026-05-25T00:02:56+00:00

Allright, I am stuck on a problem. I have about 5 database tables. One

  • 0

Allright, I am stuck on a problem.

I have about 5 database tables. One table has a list of campaigns, another has a list of ad groups, another has a list of ads, another has a list of in clicks, another has a list of leads, and another has a list of lead status.
Each table also has other columns. For example, in clicks has an ad_id and column account, and the lead status table has a lead id, buyer, and amount. Each table a column with an id associated with another table id.

So I’m trying to get my data into the following format

campaign   keyword   count(keyword)   sum(amount)   buyer
bing-auto  rap        15                45           david
google-auto honda     10                30           chris

Basically, it’s every successful lead grouped by keyword and campaign.

However, I just can’t seem to solve this problem.

SELECT keyword, COUNT(keyword) FROM in_clicks AS ic
       INNER JOIN ads AS a ON ic.ad_id = a.id
       INNER JOIN ad_groups AS ag ON a.ad_group_id = ag.id
       INNER JOIN campaigns AS c ON ag.campaign_id = c.id;
       INNER JOIN lead_status AS ls ON l.id = ls.id
       INNER JOIN leads AS l ON ic.in_click_id = l.id  
WHERE ic.create_date LIKE '%2011-08-19%' AND ic.location NOT LIKE '%Littleton%'
GROUP BY ic.keyword ORDER BY COUNT(ic.keyword) DESC

I know this is not a good explanation, and my above query is not good, but I’m a little stuck on how to proceed. Can anyone help point me in the right direction.

EDIT:
Here’s the table schema.

CAMPAIGN
id   name   trafficsource   createdate
20   hip hop   bing           2001-08-16
21   rap       bing           2001-08-18

AD GROUPS
id    name    campaignid    createdate
15    jayz      20            2001-08-16  
16    eminem    21            2001-08-18

ADS
id   headline   adgroupid
13   cool is cool   15
14   wow, great     16

IN CLICKS
id   keyword    adid   createdate
205  his name    13      2001-08-16
206  whoa        14      2001-08-18

LEADS
id   in_click_id    create_date
300    205           2001-08-16   
301    206           2001-08-18

LEAD STATUS
id    lead_id    success   amount   buyer
501    300         0        5        jack
502    300         1        15       jill
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:02:57+00:00Added an answer on May 25, 2026 at 12:02 am

    Something like this?

    SELECT 
      c.name as campaign
      , ic.keyword
      , count(ic.keyword) as keycount
      , sum(ls.amount) as total_amount
      , group_concat(ls.buyer) as buyers
    FROM in_click ic 
    INNER JOIN ads AS a ON (ic.ad_id = a.id)
    INNER JOIN ad_groups AS ag ON (a.ad_group_id = ag.id)
    INNER JOIN campaigns AS c ON (ag.campaign_id = c.id)
    INNER JOIN lead_status AS ls ON (l.id = ls.id)
    INNER JOIN leads AS l ON (ic.in_click_id = l.id)
    WHERE ic.create_date BETWEEN 2011-08-01 and 2011-08-31
          AND ic.location NOT LIKE 'test%'
    GROUP BY ic.keyword
    ORDER BY keycount
    

    Remarks
    Don’t use LIKE for datefields, use BETWEEN startdate AND enddate.
    If you use LIKE %.... you will not be able to use an index.
    Try and use LIKE cghxgs%, that way you will be able to use an index.
    If you need to do index text matches, use full text indexes with the MATCH AGAINST syntax.
    This will only work on MyISAM tables however….

    Links:
    http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between
    http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html#function_match
    http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with setting up my Zend Framework application on live server.
I have a Data Flow Task and am connecting to a database via an
Is #define LBitmap std::list < CBITMAP *> a good practice? Edit: Allright, what can
I'm stuck with a problem of changing language for the password field. In my
Alright I have a gigantic list of files I would like to copy from
I've been stuck with this problem for a few hours and can't seem to
I'm creating quite a cool image viewer but am stuck in one particular part:
Well, sorry about the confusing title but I'm having a slightly annoying problem with
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, currently I have my SWF hitting a php file that will go and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.