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 266739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:28:09+00:00 2026-05-11T23:28:09+00:00

I have two different tables, lead and click. I would like to query MySQL

  • 0

I have two different tables, lead and click. I would like to query MySQL to get the sum of the commissions generated by clicks and leads ordered by date.

Lead:

id|date      |commission
 1|2009-06-01|400
 2|2009-06-01|300
 3|2009-06-03|350

Click:

id|date      |commission
 1|2009-06-01|1
 2|2009-06-03|2
 3|2009-06-03|1

I would like to create a query that gives me (and if possible also gets date where no lead or click has been generated):

date      |commission click|commission lead|total commission
2009-06-01|               1|            700|             701
2009-06-02|               0|              0|               0
2009-06-02|               3|            350|             353

(The date is actually datetime in the real database.)

I guess I have to combine:

SELECT count(*) as number_clicks, sum(click.commission) as sum_clicks,
 date(click.time) as click_date from click group by click_date order by click_date

With:

SELECT count(*)as number_leads, sum(lead.commission) as sum_leads,
 date(lead.time) as lead_date from lead group by lead_date order by lead_date

But I can not get them to work together.

  • 1 1 Answer
  • 1 View
  • 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-11T23:28:09+00:00Added an answer on May 11, 2026 at 11:28 pm

    This doesn’t get dates with zeroes, for that you’ll either need a dates table or a stored procedure to loop through dates. One way to do it is a subselect from a union query (untested):

    SELECT commission_date, SUM(click_commission), SUM(lead_commission), SUM(total_commission)
    FROM (SELECT DATE(click.time) AS commission_date, click.commission AS click_commission,
                 0 AS lead_commission, click.commission AS total_commission
          FROM click
          UNION ALL
          SELECT DATE(lead.time) AS commission_date, 0 AS click_commission,
                 lead.commission AS lead_commission, lead.commission AS total_commission
          FROM lead) AS foo
    GROUP BY commission_date
    ORDER BY commission_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different tables from which I need to pull data blogs which
I have two different ways of displaying items in a WPF application. The first
I have two different grid controls on the same form. They share the same
I have two XML files with two different XSD schemas and different namespaces. They
I have two classes A and B in two different .NET assemblies: AssemblyA and
Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue. Why do we have two?
I have two insert statements, almost exactly the same, which run in two different
So let's say I have two different functions. One is a part of the
I have two completely different forms in one template. How to process them in
I have been given two different Microsoft Word document that my virus scanner has

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.