Hi, all

I hope somebody can help me.

Situation

Three tables
1.
+----+------------+--------+
| id | name       | region |
+----+------------+--------+
| 13 | Name1      |      1 |
| 15 | Name2      |      2 |
| 47 | Name3      |      1 |
| 57 | Name4      |      2 |
| 65 | Name5      |      2 |
| 77 | Name6      |      1 |
| 85 | Name7      |      1 |
+----+------------+--------+

2.
+----+------------+--------+----------+
| id | Date       | amount1| current  |
+----+------------+--------+----------+
| 13 | 21.7.1967  |  9900  |        N |
| 13 | 21.7.1968  |  9800  |        J |
| 57 | 11.9.1999  | 12800  |        J |
| 65 | 24.6.1991  |  1200  |        N |
| 65 | 21.7.1967  |  1275  |        J |
| 85 | 14.2.2001  | 45000  |        J |
+----+------------+--------+----------+

3.
+----+-------+--------+
| id | Year  | amount2|
+----+-------+--------+
| 13 | 1967  |   100  |
| 13 | 1968  |   100  |
| 13 | 1969  |   125  |
| 15 | 1967  |   200  |
| 15 | 1968  |   220  |
| 15 | 1969  |   220  |
| 47 | 1967  |   500  |
| 47 | 1968  |   580  |
| 47 | 1969  |   550  |
+----+-------+--------+

In table 1 there are all IDs. In tables 2 and 3 there can be some IDs.
As you see, in region 1 there are the IDs 13,47,77 and 85.
In table 2 only 13 and 85, in table 3 only 13 and 47.

What I would like to have is a result like this:
+--------+---------------------------+--------------+
| region | sum(amount1) if current=J | sum(amount2) |
+--------+---------------------------+--------------+
|   1    | 54800                     | 1630         |
|   2    | 14075                     |  640         |
+--------+---------------------------+--------------+


Many thanks in advance Joachim


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to