Suppose we have the following table, named as 'documents':
id | createDate | createBy | updateDate | updateBy
--------------------------------------------------
(various rows here)
the two *date columns are timestamps while the other are all strings (even the id
)
Currently I have the following native query used in a Spring Repository:
select COUNT(distinct(u.user_working_total))
from
(
select distinct(createBy) user_working_total
from documents
where createDate >= :startDate and
createDate <= :endDate
union
select distinct(updateBy) user_working_total
from documents
where updateDate >= :startDate and
updateDate <= :endDate
) as u
As you can see, this must be used as a native query since JPA does not support select query in the from
clause. Now I have to convert this query to a JPQL query, in order to make it database independent. Is this possible in some way?
Other approaches are welcome, like using Specification or similar...