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

  • SEARCH
  • Home
  • 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 8574529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:29:41+00:00 2026-06-11T19:29:41+00:00

The following query is working as expected. But the summary table from where the

  • 0

The following query is working as expected.
But the summary table from where the data is selected is too large. The query takes a lot of time.

SELECT s.date_time AS date_time,SUM(s.requests) AS sum_requests,SUM(s.impressions) AS sum_views,SUM(s.clicks) AS sum_clicks,SUM(s.conversions) AS sum_conversions,
SUM(s.total_revenue) AS sum_revenue,SUM(s.total_revenue)  AS sum_spend,
SUM(s.total_basket_value) AS sum_bv,SUM(s.total_num_items) AS sum_num_items,SUM(s.total_pubrevenue) AS sum_pubrevenue
FROM ox_data_summary_ad_hourly AS s 
INNER JOIN ox_banners AS d ON (d.bannerid=s.ad_id) 
INNER JOIN ox_campaigns AS m ON (m.campaignid=d.campaignid) 
INNER JOIN ox_clients AS a ON (a.clientid=m.clientid) 
LEFT JOIN ox_zones AS z ON (z.zoneid=s.zone_id) 
LEFT JOIN ox_affiliates AS p ON (p.affiliateid=z.affiliateid)
WHERE a.agencyid = 3 AND z.zone_type = 'application' AND z.delivery = 8 
AND s.date_time>='2012-07-01 00:00:00' AND s.date_time<='2012-07-01 23:59:59' 
GROUP BY date_time

I need to simplify the joins. Is there any way to create a temporary table for all joins and then join that table to the base table.
This is what I have tried so far.

drop table if exists test.helper;
create table test.helper 
select d.network_type , d.is_network, d.bannerid, p.agencyid, z.zone_type, z.delivery , z.zoneid
FROM ox_banners as d
INNER JOIN ox_campaigns AS m ON (m.campaignid=d.campaignid) 
INNER JOIN ox_clients AS a ON (a.clientid=m.clientid) 
left JOIN ox_agency as oa ON (oa.account_id = a.clientid)
left JOIN ox_affiliates AS p ON (p.agencyid = oa.agencyid)
left JOIN ox_zones AS z ON (z.affiliateid = p.affiliateid);

alter table test.helper add key(bannerid, zoneid);

But it does not return the correct results when joined with the original table.

SELECT s.ad_id, s.date_time AS date_time,SUM(s.requests) AS sum_requests,SUM(s.impressions) AS sum_views,SUM(s.clicks) AS sum_clicks,SUM(s.conversions) AS sum_conversions,
SUM(s.total_revenue) AS sum_revenue,SUM(s.total_revenue)  AS sum_spend,
SUM(s.total_basket_value) AS sum_bv,SUM(s.total_num_items) AS sum_num_items,SUM(s.total_pubrevenue) AS sum_pubrevenue
FROM ox_data_summary_ad_hourly AS s 
inner JOIN test.helper  AS d ON (d.bannerid=s.ad_id )
where d.agencyid = 3 AND d.zone_type = 'application' AND d.delivery = 8  and s.date_time>='2012-07-01 00:00:00' AND s.date_time<='2012-07-01 23:59:59' 
GROUP BY date_time
  • 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-06-11T19:29:42+00:00Added an answer on June 11, 2026 at 7:29 pm

    Firstly, I’d replace the LEFT JOINs with INNER JOINS. Since you have a WHERE clause on ox_zones, the null values created by the LEFT JOIN will drop out anyway. Outer joins are obviously expensive, and should be avoided where possible.

    On a reasonable, modern RDBMS, second-guessing the query planner by creating temporary tables is often counter-productive. Are all your join conditions indexed? Are the columns referenced in your WHERE clause indexed?

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

Sidebar

Related Questions

The following query is working as expected. But how do I get the results
I have the following query which is working fine, but I also want to
I have the following xpath query which seems to be working but I just
I have the following query working: SELECT DISTINCT table1.field1, table1.field2 FROM table1 WHERE table1.field3
I'm trying to run the following statement but it is not working as expected.
I have the following query working on sql server managemengt studio but it does
I expected the following LINQ query to sort according to FirstName but the OrderBy
I have the following command that's kind of working as expected: DBSession.query(Users).filter(or_(Users.first_name.contains(search_term),Users.last_name.contains(search_term))).all() I searches
I am trying to select the following query from my table: SELECT ARTICLE_NO, USERNAME,
Working SQL The following code works as expected, returning two columns of data (a

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.