1

I have three seperate table without any foregin key or relations each.. database three table

I need a Summary like this should be summary display like this

Now, what and how will be mysql query.. I am very new web developer... please kindly lets me know details. pleas help me on this issues

refference links :: https://stackoverflow.com/questions/6676653/mysql-query-two-tables-get-data-in-date-wise-or-user-wise

Anwar
  • 13
  • 3

1 Answers1

0

Here is one approach I've used in the past. I think this will help you with the basics. I've only included 2 of the tables, adding the third should help you to understand the answer rather than copy/paste it.

(You'll need to change the first line to add references to sum(Costings), and add a 'union' 'select ... from bank_mobile_costing', in addition to adding a reference 'Costing' column to the 'Investments' and 'Earnings' select statements.)

select date,sum(Investments),sum(Earnings),sum(Investments+Earnings) as Balance from
(
select date,amount as 'Investments',0.0 as 'Earnings' from bank_mobile_investments
union
select date,0.0,amount from bank_mobile_earnings 


) mydata 
group by date
order by 1

It's worth my noting here that this will NOT display a list of calendar dates in the date column, but rather it displays a complete list of all the dates which exist in your 3 tables; I don't know if that's appropriate to your needs.

On the subject of your running total column at the end, this is a convoluted subject but a quick google search yields the following stack overflow result which gives a couple of methods of doing it, and there are some interesting points raised in the comments about the advantages or drawbacks of the methods.

Calculate a Running Total

chrlsuk
  • 59
  • 2