Q:

Oracle SQL query for distribution

I have a table PROCESSES with columns PR_ID, PR_FROM, PR_TO.  PR_ID is process identifier and PR_FROM and PR_TO timestamps defining when process started and when it finished. 
Now I'd like to create an Oracle SQL query which will represent how many processes lasted 0-1 hour, how many lasted 1-2 hours and so on.  How to create such a query? 

A:

I found the answer myself (distribution within 24 hours):
SELECT h,COUNT(pr_id) n
FROM (SELECT LEVEL AS h FROM DUAL CONNECT BY LEVEL <= 24)
LEFT JOIN processes ON h=(EXTRACT(HOUR FROM (PR_TO-PR_FROM))+1)
GROUP BY h
ORDER BY h

distribution from 0 to max value:
SELECT h,COUNT(pr_id) n
FROM (SELECT LEVEL AS h FROM DUAL CONNECT BY LEVEL <= ((SELECT MAX(EXTRACT(HOUR FROM (PR_TO-PR_FROM))+1) FROM processes)))
LEFT JOIN processes ON h=(EXTRACT(HOUR FROM (PR_TO-PR_FROM))+1)
GROUP BY h
ORDER BY h

Robert helped a lot.