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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:31:35+00:00 2026-05-15T20:31:35+00:00

So, I need some code help. I’ve got an awkward little MySQL table that

  • 0

So, I need some code help.
I’ve got an awkward little MySQL table that just keeps growing and growing.

Let’s assume that a set of clients, some in certain countries, that I need to ‘total’ the invoices for (need to calculate GST)

So, two tables contain the data I need — one table has their ID and their country (In this case, Canada!).
In our second table I’ve got their invoices, of which one variable is their ID from table1, and the another variable I’ve got to retrieve (and sum).
Note it would help if they were summed into quarters. Invoices also have a duedate in the following syntax: 2006-06-26 (year-month-day).

In table 1 the ID set for each client is named: id — it’s numeric, e.g. 1-200000
In table 1 the country is: CA

In table 2 the variable for duedates is: duedate
The other variable we require is the subtotal

Out of table2 I need to basically only grab whichever clients are in country CA (data from table1) and SUM their invoices.

The output should be as follows:
1st quarter sum: $x,xxx
2nd quarter sum: $x,xxx
How?

  • 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-15T20:31:36+00:00Added an answer on May 15, 2026 at 8:31 pm

    You can handle this in mysql entirely:

    SELECT 
      CONCAT('Q', QUARTER(inv.duedate), ' ', YEAR(inv.duedate)) as quarter,
      SUM(inv.total) as total
    FROM
      invoices inv
      LEFT JOIN clients cli ON inv.client_id = cli.id 
    WHERE
      cli.country = 'CA'
    GROUP BY
      quarter
    

    Output:

    +---------+--------+
    | quarter | total  |
    +---------+--------+
    | Q1 2010 | 110.40 |
    | Q2 2010 |  10.20 |
    +---------+--------+
    2 rows in set (0.00 sec)
    

    My Test Data:

    CREATE TABLE `clients` (
      `id` int(11) NOT NULL,
      `country` varchar(3) DEFAULT NOT NULL
    );
    INSERT INTO `clients` VALUES (1,'CA');
    
    CREATE TABLE `invoices` (
      `client_id` int(11) NOT NULL,
      `duedate` date DEFAULT NOT NULL,
      `total` decimal(10,2) DEFAULT NOT NULL
    );
    
    INSERT INTO `invoices` VALUES (1,'2010-01-01','100.20'),(1,'2010-05-01','10.20'),(1,'2010-03-01','10.20');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Marko's solution is the way to go for simple cases.… May 16, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer You could extend EditTextPreference: public class IntEditTextPreference extends EditTextPreference {… May 16, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer When you want to have colored panels under a themed… May 16, 2026 at 11:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need some code to zoom an image when i mouse over that image,
I'm a student and I got a homework i need some minor help with
I need some help tweaking this php code to print out a default value
I need some help to store a Object in an SQLite database using Android.I
I need some help using LINQ to filer a list of files based on
I am learning C++ and need some help with compile error messages. I have
I am a bit new to sql and php so I need some help
I'm not very good with CSS and I need some help. I have a
i want to know how to use ListView.FixedViewInfo, so i need some code spinet
I have written some code that pulls info from a plist file and does

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.