I have oracle backend for my application. The schema is designed such that I have user transactions split into 12 monthly transaction tables.. one for each month. Now I want to retrieve the top 10 users who have accessed highest number of distinct documents in a given date range.
I currently have a query which does countDistinct on documents for each user,sort in desc order of this count and select top 10 results from this.
I run this query over each table and all results are appended in a list. I have to scan this list and do a sum on monthly count and then group by user_id to get the document totals for each user across all 12 months.
I realised that this count is not the right count since there may be same documents accessed by same user in different months. with my current logic these count will get added up.
I need to know which strategy should I use so that the result will be the most accurate.. I know one way would be to query from single table, which will definitely give me right answer but can I achieve this same-result from querying all 12 tables?
here is a sample monthly table for january
class TxnSummJan {
Long id
Transaction trans
Users grauser
Resources graresource
Integer transactioncount
Date lastaccesseddate
Date currentdate
String accountid
String userlocation
String documentname
String eventdesc
}
Similar tables for each month..
its me again.
Could you apply
UNION ALLto all 12 tables and then make it into a view?