Hi harold, I did something like this a few years ago to capture some retrieval metrics.
Granted this was on AIX, maybe it will be of some value. I actually used ARSDOC get, piped it to a file, then used a combo of sed/awk to parse it out.. Maybe that could help you instead of a database query? I did something like -i "where msg_num in ('66', 65') ... etc.
This was actually suggested by someone at IBM.