Jump to content

MySQL Result from the same table


ClickBuddy
Go to solution Solved by Barand,

Recommended Posts

I have a table with the following relevant fields:

 

ID, BRN, CRED, AMT, USER

 

A basic explanation would be:

BRN = Branch

CRED = Creditor

AMT = Amount

USER = Debtor

 

What I want to do is get a result where I get the total amount (AMT) owed to each Creditor, which is easy, but I want the result to include the total owed by each branch. Now it has been a while since I have worked with JOINS and I only have a limited knowledge of working with SQL. so any help is appreciated.

 

SELECT SUM(t1.AMT) AS TOTAL, t1.CRED
FROM `201105` t1 INNER JOIN 
	(
		SELECT SUM(t1.AMT),t1.BRN
		FROM `201105` t1
		GROUP BY t1.BRN
	) t2 ON t1.CRED = t2.CRED
GROUP BY t1.CRED

Which gives me errors :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.