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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:30:14+00:00 2026-05-20T11:30:14+00:00

I have three tables like this CREATE TABLE `money`.`categories` ( `ID` bigint(20) unsigned NOT

  • 0

I have three tables like this

CREATE TABLE  `money`.`categories` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `Title` text NOT NULL,
  PRIMARY KEY (`ID`)
)

CREATE TABLE  `money`.`expenditure` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `Purpose` text NOT NULL,
  `Amount` bigint(20) unsigned NOT NULL,
  `Date` datetime NOT NULL,
  `CategoryID` bigint(20) unsigned NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `FK_expenditure_1` (`CategoryID`),
  CONSTRAINT `FK_expenditure_1` FOREIGN KEY (`CategoryID`) REFERENCES `categories` (`ID`)
)

CREATE TABLE  `money`.`income` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `Source` text NOT NULL,
  `Amount` bigint(20) unsigned NOT NULL,
  `Date` datetime NOT NULL,
  PRIMARY KEY (`ID`)
)

It is actually not complicated at all. Very simple.

I have three queries to find

  1. the sum of income for a particular month:
    select sum(amount) tot_inc from money.income ic where month(ic.date) = 02;

  2. sum of expenditure for a particular month:
    select sum(amount) tot_exp from money.expenditure ex where month(ex.date) = 02;

  3. sum of expenditure for a particular month in a particular category:
    select sum(amount) tot_exp from money.expenditure ex where month(ex.date) = 02 and ex.categoryid = 3;

I have two questions:

  1. How can I find out the percentage of total income that has gone away as total expenditure for a particular month. Basically I want to find out (100*tot_exp/tot_inc) from queries 1 and 2. but how can I write it in query?

  2. Building on top of that, I want to find out how much percentage each category of expenditure contributed to ina particular month. I understand it is a combination of group by and aggregate and/or math functions but I can’t even begin to visualize how the query should be written. How can I get these numbers?

  • 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-20T11:30:15+00:00Added an answer on May 20, 2026 at 11:30 am
    SELECT 
    (100*(SELECT SUM(amount) tot_inc FROM money.income ic WHERE month(ic.date) = "02")/SUM(amount)) AS "Result"
    FROM expenditure e 
    WHERE MONTH(ex.date) = "02"
    GROUP BY CategoryID
    HAVING result > 10
    

    I think it would be something like this

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

Sidebar

Related Questions

I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
Say I have a schema that represents a fixed-depth hierarchy like this: CREATE TABLE
This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent`
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables. This query will write down the right answer (x-lines for
I have three tables tag , page , pagetag With the data below page
Assuming I have three tables : TableA (key, value) TableB (key, value) TableC (key,
Well here's my problem I have three tables; regions, countries, states. Countries can be
I have a MySQL Left Join problem. I have three tables which I'm trying

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.