I’ve a resultset which sums the totals for N situations and N different codes for a certain period.
Data comes from this SQL
SELECT *, count(fldA) as ca
FROM table
WHERE ('... month/year ...')
GROUP BY Sit, Cod
ORDER BY count(fldA) DESC;
Ok here’s the table I want:
+--------------------------------+
| d/l | Sit. A | Sit. B | Sit. N |
+-----+--------+--------+--------+
| c91 | 10 | 05 | 10 |
+-----+--------+--------+--------+
| c93 | 15 | | |
+-----+--------+--------+--------+
| cN. | 07 | 01 | |
+-----+--------+--------+--------+
| Tot | 22 | 06 | 10 |
+--------------------------------+
So the corresponding array (resultset) for the table above should be something like:
SitA, C93, 15;
SitN, c91, 10;
SitA, c91, 10;
SitA, CN., 07;
SitB, c91, 05;
SitB, cN., 01;
Note that number of situations (Collumns) and codes (Rows) WILL VARY. And there are cases where in the resultset array there should be NO value for some col x row combination.
Obviously, the totals should be calculated afterwards.
The question is… which is the best approach for this type of resultset => table creation? Preferably using only one SQL request.
So, since no help comes… i’ve done this
…
We interact throught the two ‘buffers’ for collumns and rows setting a sql to calculate each cell at a time…
gl, thx
Paulo Bueno.