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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:04:50+00:00 2026-05-15T05:04:50+00:00

Hey guys, I have a program that allows me to run queries against a

  • 0

Hey guys, I have a program that allows me to run queries against a large database.
I have two tables that are important right now, Deposits and withdraws. Each contains a history of every user. I need to take each table, add up every deposit and withdraws (per user), then subtract the withdraws from the deposits. I then need to return every user whos result is negative (aka they withdrew more then they deposited).
Is this possible in one query?
Example:

Deposit Table:
|ID|UserName|Amount| |1 | Use1 |100.00| |2 | Use1 |50.00 | |3 | Use2 |25.00 | |4 | Use1 | 5.00 |

WithDraw Table: |ID|UserName|Amount| |2 | Use2 | 5.00 | |1 | Use1 |100.00| |4 | Use1 | 5.00 | |3 | Use2 |25.00 |

So then the result would output: |OverWithdrawers| | Use2 |

Is this possible (I sure don’t know how to do it)?
Thanks for any help,
Max

  • 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-15T05:04:51+00:00Added an answer on May 15, 2026 at 5:04 am

    Try this:

    SELECT T1.UserName
    FROM
    (
        SELECT UserName, SUM(Amount) AS Amount
        FROM WithDraw
        GROUP BY UserName
    ) T1
    LEFT JOIN
    (
        SELECT UserName, SUM(Amount) AS Amount
        FROM Deposit
        GROUP BY UserName
    ) T2
    ON T1.UserName = T2.UserName
    WHERE T1.Amount > COALESCE(T2.Amount, 0)
    

    The COALESCE is so that it also works if there are users that have withdrawn but never deposited.

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

Sidebar

Related Questions

Hey guys, I have a program that uses ajax to send a post to
hey guys, beginner here. I have written a program that outputs files to .txt's
Hey guys, I'm getting a really strange error. I have a program that needs
Hey guys I have an admin page that checks if you are admin before
Hey guys I have one more question lol. I am using a script that
Hey guys I have a query that currently finds the latest comment for each
Hey guys, I have developed a small site that i would like to embed
Hey guys i have two date inputs containing three dropboxes for day,month and year
Hey guys i have a ListActivity... a very simple at that... and it keeps
Hey guys I have an older site that is coded in AS2(I can't get

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.