Subject Query problem
Author doru@oltenita.de
The table:
|----|-----|-----|------|-----|
| ID | AAA | BBB | CCC | DDD |
|----|-----|-----|------|-----|
| 1 | xxx | yyy | 1000 | 0 |
| 2 | xxx | zz1 | 111 | 400 |
| 3 | xxx | zz2 | 222 | 200 |
| 4 | xxx | kkk | 2000 | 0 |
| 5 | xxx | zz3 | 333 | 100 |
|----|-----|-----|------|-----|

ID integer PK
AAA char(10)
BBB char(10)
CCC numeric(10)
CCC numeric(10)


How can I do this in a single query (a view may by), or (the last thing to do) in a stored procedure:

The corect result:
|-----|-------|-----|-----|-----|-----|-----|-----|
| AAA | CCC1 | D11 | D12 | D21 | D22 | D31 | D32 |
|-----|-------|-----|-----|-----|-----|-----|-----|
| xxx | <...> | 400 | 111 | 200 | 222 | 100 | 333 |
|-----|-------|-----|-----|-----|-----|-----|-----|

<...> --> (sum(CCC) where DDD = 0) - (sum(DDD))

Thank you.

[Non-text portions of this message have been removed]