### Thread: Query problem

1. #### Query problem

The table:
Code:
```|----|-----|-----|------|-----|
| 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)
DDD 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:
Code:
```|-----|-------|-----|-----|-----|-----|-----|-----|
| AAA | CCC1  | D11 | D12 | D21 | D22 | D31 | D32 |
|-----|-------|-----|-----|-----|-----|-----|-----|
| xxx | <...> | 400 | 111 | 200 | 222 | 100 | 333 |
|-----|-------|-----|-----|-----|-----|-----|-----|

<...> --> (sum(CCC) where DDD = 0) - (sum(DDD))```
Thank you.
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
62
Rep Power
16
Seems that you need somethink like cross-tab query. If I remember correctly and you use VFP8, there is a program that does something like this. Also in Universal Thread forum is MatxTab.prg to download. If you can translate code in some SPs, maybe you can do it. I believe that is not something so easy to do.
3. Anny sugestions? pleaseeeeee