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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:45:05+00:00 2026-05-28T04:45:05+00:00

This is a follow-up to a previous questions I asked: Using a GROUP BY

  • 0

This is a follow-up to a previous questions I asked: Using a GROUP BY statement to sum rows. I have a table with sales of different currencies, and I am using a GROUP BY statement to sum up the numbers per title.

mysql> SELECT
       title, 
       SUM(us_earnings_usd) AS usd,
       SUM(cad_earnings_cad) AS cad,
       SUM(uk_earnings_gbp) AS gbp,
       SUM(swedish_earnings_skk) AS skk
       FROM raw_financials 
       WHERE date="2012-12-01"
       GROUP BY title

+--------+-----------------+------------------+------------------+------------------+
| title  | us_earnings_usd | cad_earnings_cad |swedish_earnings_ |  uk_earnings_gbp |
+--------+-----------------+------------------+------------------+------------------+
| Gamers |          7.7500 |           4.0000 |           1.0000 |           2.0000 |
+--------+-----------------+------------------+------------------+------------------+

Finally, I need to sum up the fields to get the total sales in USD. For this, I have an additional table called exchange_rates. This is how it can be queried:

mysql> SELECT currency, conversion_to_usd FROM exchange_rates WHERE date="2011-12-01";

+----------+-------------------+
| currency | conversion_to_usd |
+----------+-------------------+
| AUD      |           0.98542 |
| CAD      |           0.95940 |
| CHF      |           1.05235 |
| DKK      |           0.17372 |
| EUR      |           1.29400 |
| GBP      |           1.54223 |
| NOK      |           0.16579 |
| NZD      |           0.74442 |
| SEK      |           0.14190 |
| USD      |           1.00000 |
+----------+-------------------+

How would I combine these using SQL to get:

total_earnings_in_usd = 7.75 (earnings in usd) *1.00 (conversion from usd to usd) 
                        + 4.00 (earnings in cad) *0.95 (conversion from cad to usd) 
                        + 1.00 (earnings in sek) *0.14 (conversion from sek to usd)
                        + 2.00 (earnings in gbp) *1.54 (conversion from gbp to usd) 
                      = $14.77 USD

Update: I have updated the SQL in the question.

  • 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-28T04:45:06+00:00Added an answer on May 28, 2026 at 4:45 am

    UPDATED FOLLOWING COMMENT

    SELECT  title, 
            partner_share_currency,
            SUM(us_earnings_usd) AS usd,
            SUM(cad_earnings_cad) AS cad,
            SUM(us_earnings_usd) + SUM(cad_earnings_cad*CAD) +
            SUM(uk_earnings_gbp*GBP) + SUM(swedish_earnings_skk*SEK) total_earnings_in_usd
    FROM raw_financials rf
    LEFT JOIN ( SELECT  date, 
                        MIN(CASE WHEN  currency = 'CAD' THEN conversion_to_usd END) CAD,
                        MIN(CASE WHEN  currency = 'GBP' THEN conversion_to_usd END) GBP,
                        MIN(CASE WHEN  currency = 'SEK' THEN conversion_to_usd END) SEK
                FROM exchange_rates 
                WHERE currency IN ('CAD','GBP','SEK')
                GROUP BY date) er
    ON rf.date = er.date
    WHERE title LIKE '%Gamers%' AND rf.date= '2012-12-01'
    GROUP BY title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This follows my previous questions on using lxml and Python. I have a question,
This is a follow up to one of my previous questions and I have
This is a follow up question to a previous question I asked about calculating
This is a follow-up questions on a previous one . Consider this code, which
So this is a follow-up to a previous question that I asked: Trying to
I realise this question has been asked before however the previous answers have gotten
This is a follow-up to my previous questions ( Copy Update Create VBScript and
This is a follow up to a previous question I asked How to encode
This is a continuation question from a previous question I have asked I now
this is a follow up question of my previous question So I have this

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.