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 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
  • 2 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...users, user_info, and quota_levels. They look like this: CREATE TABLE users
So I have three tables: CREATE TABLE tblUser ( [pkUserID] [int] IDENTITY(1,1) NOT NULL,
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have three tables. The designs were like student table create table student (studID
Hi there I have an SQL table that looks like this: CREATE TABLE IF
there are three existing tables defined like the following: create table business_units (id number(10,0)
I have three tables: categories, languages and categories_languages. Categories_languages is many to many table
I have a table like this: <table id='inventory_table'> <tr id='no_items_avail'> <td> There are no
I have three tables CLASSES , CHILD_CLASSES , and STUDENTS . CLASSES looks like

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.