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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:45:33+00:00 2026-05-27T19:45:33+00:00

So I store all transactions in a transaction table with the following struture: +—————-+—————+——+—–+———+—————-+

  • 0

So I store all transactions in a transaction table with the following struture:

+----------------+---------------+------+-----+---------+----------------+
| Field          | Type          | Null | Key | Default | Extra          |
+----------------+---------------+------+-----+---------+----------------+
| debit_amount   | decimal(10,2) | YES  |     | 0.00    |                | 
| credit_amount  | decimal(10,2) | YES  |     | 0.00    |                | 
| flag           | int(11)       | YES  |     | NULL    |                | 
| date           | datetime      | YES  |     | NULL    |                | 
| id             | int(11)       | NO   | PRI | NULL    | auto_increment | 
+----------------+---------------+------+-----+---------+----------------+

Then I store the total amount of credits the user has in the “credits” row in the user table.

I am trying to figure out whether there is a mismatch in the total(debit amount + credit amount) for each user as stored in the transactions table to the number of credits stored in the user table.

basically for each user

 transactions.debit_amount + transactions.credit amount MUST EQUAL user.credits

but the does not equal operator in the mysql query does not work (especially when the transactions.total is null i.e. there is no row in the transactions table for that user):

SELECT s.id AS uid, s.total, s.credits
FROM (
  SELECT (sum(t.credit_amount) + sum(t.debit_amount)) AS total, t.userid, u.credits, u.id
  FROM transactions AS t
  RIGHT JOIN users AS u ON t.userid = u.id 
  GROUP BY u.id
) AS s
WHERE s.total != s.credits
  • 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-27T19:45:34+00:00Added an answer on May 27, 2026 at 7:45 pm

    Try:

    select u.id, u.credits, t.total
    from  users u
    left join (
        select userid, sum(coalesce(credit_amount,0)) + sum(coalesce(debit_amount, 0)) as total
        from transactions
        group by userid
    ) t on u.id = t.userid
    where coalesce(t.total, 0) <> coalesce(u.credits, 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our application has a table which stores all transactions records of clients in one
I have a database table transaction which stores all the transaction made by users
I need a table to store the state of a financial transaction. The state
I normally store all my configs in the registry. Even though I have started
I was attempting to store all the JMS object of the class Message recieved
I want to store all of the data that is kept in encoding_symbols_tab [0]
We have a requirement in project to store all the revisions(Change History) for the
Is there any way to make Visual Studio 2008 Express store all the files
What would be the best data structure to store all the words of a
In my app I use a static database to store all counties and census

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.