Jump to content

MySQL Result from the same table


ClickBuddy

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
https://forums.phpfreaks.com/topic/275811-mysql-result-from-the-same-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.