Hi Dastan,
Those individual totals can be calculated using the UI in Report Builder (RB). Select the artifact you want the totals of (Work Item, Test Case). Add the conditions needed, if any (e.g. Creation Date, Iteration). In the Format Results page add a calculated column that counts the total of artifacts. At this point you can look at the Advanced SQL section and see the SQL generated by RB. For your calculation, you will have to put together those two SQL statements and then do the division to calculate the density.
In the Advanced SQL section you can enter any SELECT statement you need to query the data warehouse. You can use the auto generated SQL statements to verify in which tables the data is, and see how some of the OOTB calculations are made. If you require further assistance, please contact IBM Support.
Thank you,
Clara