Category Table
mysql> SELECT * FROM cats;
+------+-----------+
| c_id | c_name |
+------+-----------+
| 1 | cats 1 |
| 2 | cats 2 |
| 3 | cats 3 |
+------+-----------+
Meta Table
mysql> SELECT * FROM meta;
+------+------+----------+-------------+-------+
| m_id | c_id | name | description | costs |
+------+------+----------+-------------+-------+
| 1 | 1 | Abhijit1 | description | 100 |
| 2 | 1 | Abhijit2 | description | 200 |
| 3 | 2 | Abhijit3 | description | 500 |
| 4 | 3 | Abhijit4 | description | 800 |
+------+------+----------+-------------+-------+
meta and cats table common is c_id meta table cats c_id(1) meta table have 2 (Abhijit1,Abhijit2) row with m_id(1,2)
Transaction Table
mysql> SELECT * FROM transactions;
+------+------+------------+--------+
| t_id | m_id | date | amount |
+------+------+------------+--------+
| 1 | 1 | 2016-02-01 | 50 |
| 2 | 1 | 2016-02-06 | 50 |
| 3 | 3 | 2016-02-15 | 400 |
| 4 | 4 | 2016-02-19 | 150 |
+------+------+------------+--------+
transactions and meta table common is m_id transactions for m_id 1 have 2 row t_id(1,2) this table mainly for paid amount and date
I want to sum() for each category all costs (from meta table) and amount( from transaction table).
tables are connect with
cats.c_id
|
|-----> meta.c_id
|-----> meta.m_id
|-----> transactions.m_id
It's wrong. The Costs of cats id 1 is 300 but here I got 400
I Want Get Return From Query Like This:
+------+-----------+--------------+---------------+
| c_id | c_name | SUM(m.costs) | SUM(t.amount) |
+------+-----------+--------------+---------------+
| 1 | cats 1 | 300 | 100 |
| 2 | cats 2 | 500 | 400 |
| 3 | cats 3 | 800 | 150 |
+------+-----------+--------------+---------------+
Here SUM(m.costs) are all Cost For a category and SUM(t.amount) are all paid for a category
Please help me or any better Idea for Table management.
SUM(t.amount)for category 1 be 100 (50+50)?