I am working on a some extensions to Gerrit. I have the following query to get the TOTAL COMMITS, TOTOAL REVIEW COMMENTS…etc for a particular ACCOUNT_ID from the gerrit DB.
with
changeids as
(select change_id from PATCH_SETS where UPLOADER_ACCOUNT_ID=1001961),
patchcommentstoothers as
(select count(*) c from patch_comments where AUTHOR_ID!=1001961 AND Change_id in (select change_id from changeids)),
ownerchanges as
(select count(*) c from changes where owner_account_ID=1001961 and OPEN='Y'),
changemessages as
(select count(*) c from change_messages where AUTHOR_ID=1001961 and change_id not in (select change_id from changeids))
select pcto.c TOT_PATCH_COMMENTS, oc.c TOT_CHANGES, cm.c TOT_CHANGE_MESSAGES
from patchcommentstoothers pcto, ownerchanges oc, changemessages cm;
Now with the above query I can get the three counts for one user. I want to run the above query for all ACCOUNT_ID’s. Something like run this query for each account (not just for 1001961 here) and get back all the records in one go for all accounts.
ACCOUNT table has the following columns:
"REGISTERED_ON" TIMESTAMP (6) NOT NULL ENABLE,
"FULL_NAME" VARCHAR2(255 BYTE),
"PREFERRED_EMAIL" VARCHAR2(255 BYTE),
"CONTACT_FILED_ON" TIMESTAMP (6),
"MAXIMUM_PAGE_SIZE" NUMBER(6,0) DEFAULT 0,
"SHOW_SITE_HEADER" CHAR(1 BYTE) DEFAULT 'N',
"USE_FLASH_CLIPBOARD" CHAR(1 BYTE) DEFAULT 'N',
"DOWNLOAD_URL" VARCHAR2(20 BYTE),
"DOWNLOAD_COMMAND" VARCHAR2(20 BYTE),
"COPY_SELF_ON_EMAIL" CHAR(1 BYTE) DEFAULT 'N',
"DATE_FORMAT" VARCHAR2(10 BYTE),
"TIME_FORMAT" VARCHAR2(10 BYTE),
"INACTIVE" CHAR(1 BYTE) DEFAULT 'N',
"ACCOUNT_ID" NUMBER(11,0) DEFAULT 0
I would prefer not to use procedures.
P.S. – I suck at Oracle SQL.
The CTEs now calculate the values for every user.
The final select assumes that you have a
usertable that lists all of your users.If you filter the final query by user, the CTEs will only calculate the results for the users in the final results.