I have produced a cross tab style query using the following SQL;
SELECT uio.owning_organisation,
COUNT(DECODE(pu.progress_code,'AA',pu.person_code,NULL)) AA,
COUNT(DECODE(pu.progress_code,'AACK',pu.person_code,NULL)) AACK,
COUNT(DECODE(pu.progress_code,'SCH',pu.person_code,NULL)) SCH
FROM
people_units pu,
unit_instance_occurrences uio
WHERE
pu.uio_id = uio.uio_id AND
pu.unit_type = 'A' AND
pu.calocc_code = '0708'
GROUP BY
uio.owning_organisation
ORDER BY
uio.owning_organisation
This works perfectly well, but ive had to hard code the values of progress_code into the query. These may be added to. If new codes are added to the system I will have to manually update this query each time. Is there a way of producing a cross tab style output where you dont necessarily know all the possible column values?
SELECT uio.owning_organisation,
COUNT(DECODE(pu.progress_code,'AA',pu.person_code,NULL)) AA,
COUNT(DECODE(pu.progress_code,'AACK',pu.person_code,NULL)) AACK,
COUNT(DECODE(pu.progress_code,'SCH',pu.person_code,NULL)) SCH
FROM
people_units pu,
unit_instance_occurrences uio
WHERE
pu.uio_id = uio.uio_id AND
pu.unit_type = 'A' AND
pu.calocc_code = '0708'
GROUP BY
uio.owning_organisation
ORDER BY
uio.owning_organisation
This works perfectly well, but ive had to hard code the values of progress_code into the query. These may be added to. If new codes are added to the system I will have to manually update this query each time. Is there a way of producing a cross tab style output where you dont necessarily know all the possible column values?